-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat : create chatbot using openai and springai #59
Conversation
WalkthroughThe updates introduce enhancements to existing functionalities and add new features such as improved exception handling, comprehensive test configurations, and integration of new APIs. The configuration updates span multiple files, setting up Maven, Spring Boot components, and logging mechanisms. These changes aim to streamline build processes, enhance chatbot interaction using AI, and ensure robust testing with added support for various components. Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (3)
chatbot/chatbot-ollama-springai/pom.xml
is excluded by!**/*.xml
chatbot/chatbot-openai-springai/pom.xml
is excluded by!**/*.xml
chatmodel-springai/pom.xml
is excluded by!**/*.xml
Files selected for processing (19)
- .github/workflows/chatbot-ollama-springai.yml (2 hunks)
- .github/workflows/chatbot-openai-springai.yml (1 hunks)
- chatbot/chatbot-openai-springai/.gitignore (1 hunks)
- chatbot/chatbot-openai-springai/.mvn/wrapper/maven-wrapper.properties (1 hunks)
- chatbot/chatbot-openai-springai/ReadMe.md (1 hunks)
- chatbot/chatbot-openai-springai/mvnw (1 hunks)
- chatbot/chatbot-openai-springai/mvnw.cmd (1 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/ChatbotOpenaiApplication.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/config/ChatConfig.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/config/CustomClientHttpResponse.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/config/LoggingConfig.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/config/SwaggerConfig.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/controller/ChatbotController.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/model/request/AIChatRequest.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/model/response/AIChatResponse.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/service/ChatbotService.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/resources/application.properties (1 hunks)
- chatbot/chatbot-openai-springai/src/test/java/com/example/chatbot/ChatbotOpenaiApplicationTests.java (1 hunks)
- chatbot/chatbot-openai-springai/src/test/java/com/example/chatbot/TestChatbotOpenaiApplication.java (1 hunks)
Files not reviewed due to errors (1)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/config/ChatConfig.java (no review received)
Files skipped from review due to trivial changes (9)
- .github/workflows/chatbot-ollama-springai.yml
- .github/workflows/chatbot-openai-springai.yml
- chatbot/chatbot-openai-springai/.gitignore
- chatbot/chatbot-openai-springai/.mvn/wrapper/maven-wrapper.properties
- chatbot/chatbot-openai-springai/mvnw.cmd
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/ChatbotOpenaiApplication.java
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/model/request/AIChatRequest.java
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/model/response/AIChatResponse.java
- chatbot/chatbot-openai-springai/src/main/resources/application.properties
Additional Context Used
Markdownlint (2)
chatbot/chatbot-openai-springai/ReadMe.md (2)
3: Expected: 1; Actual: 2
Multiple consecutive blank lines
48: null
Files should end with a single newline character
Additional comments not posted (7)
chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/config/SwaggerConfig.java (1)
8-10
: Configuration for Swagger is correctly set up with appropriate annotations.chatbot/chatbot-openai-springai/src/test/java/com/example/chatbot/TestChatbotOpenaiApplication.java (1)
6-12
: Test configuration for the chatbot application is correctly set up using Spring Boot's testing utilities.chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/controller/ChatbotController.java (1)
11-24
: REST controller for AI chat requests is correctly implemented with appropriate Spring annotations and method definitions.chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/service/ChatbotService.java (1)
14-33
: Service class for processing AI chat requests is correctly implemented with appropriate logging and null handling.chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/config/CustomClientHttpResponse.java (1)
13-46
: Custom HTTP response handling is correctly implemented with appropriate header modifications and method overrides.chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/config/LoggingConfig.java (1)
26-40
: Validate the necessity of custom HTTP response wrapper.The use of
CustomClientHttpResponse
might introduce overhead or unexpected behavior. Verify that this custom implementation is necessary and correctly handles all HTTP aspects like status codes, headers, and body.chatbot/chatbot-openai-springai/mvnw (1)
45-79
: Ensure compatibility with non-standard Java installations.The script includes specific handling for IBM's JDK on AIX. Verify that this custom handling is tested and works correctly across all supported platforms.
@BeforeAll | ||
void setUp() { | ||
RestAssured.port = localServerPort; | ||
} | ||
|
||
@Test | ||
void chat() throws StreamReadException, DatabindException, IOException { | ||
|
||
Response response = given().contentType(ContentType.JSON) | ||
.body(new AIChatRequest( | ||
"As a cricketer, how many centuries did Sachin Tendulkar scored adding up both One Day International (ODI) and Test centuries ?", | ||
null)) | ||
.when() | ||
.post("/api/ai/chat") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.contentType(ContentType.JSON) | ||
.body("answer", containsString("100")) | ||
.log() | ||
.all(true) | ||
.extract() | ||
.response(); | ||
|
||
AIChatResponse aiChatResponse = objectMapper.readValue(response.asByteArray(), AIChatResponse.class); | ||
System.out.println("conversationalId :: " + aiChatResponse.conversationId()); | ||
|
||
given().contentType(ContentType.JSON) | ||
.body(new AIChatRequest( | ||
"How many One Day International (ODI) centuries did he scored ?", | ||
aiChatResponse.conversationId())) | ||
.when() | ||
.post("/api/ai/chat") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.contentType(ContentType.JSON) | ||
.body("answer", containsString("49")) | ||
.log() | ||
.all(true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor test cases to reduce redundancy.
The test cases for different chat scenarios are very similar and could be refactored into a single parameterized test method to reduce redundancy and improve maintainability.
@@ -0,0 +1,48 @@ | |||
# chatbot-openapi-springai | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra blank line to adhere to markdown best practices.
-
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
ChatbotService-->>ChatbotController: response | ||
ChatbotController-->>User: response | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure the file ends with a single newline character.
+
Committable suggestion was skipped due low confidence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
chatbot/chatbot-openai-springai/pom.xml
is excluded by!**/*.xml
Files selected for processing (6)
- chatbot/chatbot-ollama-springai/src/test/java/com/example/chatbot/ChatbotOllamaApplicationTests.java (2 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/config/ChatConfig.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/service/ChatbotService.java (1 hunks)
- chatbot/chatbot-openai-springai/src/main/resources/application.properties (1 hunks)
- chatbot/chatbot-openai-springai/src/test/java/com/example/chatbot/ChatbotOpenaiApplicationTests.java (1 hunks)
- chatbot/chatbot-openai-springai/src/test/java/com/example/chatbot/TestChatbotOpenaiApplication.java (1 hunks)
Files skipped from review due to trivial changes (1)
- chatbot/chatbot-ollama-springai/src/test/java/com/example/chatbot/ChatbotOllamaApplicationTests.java
Additional comments not posted (14)
chatbot/chatbot-openai-springai/src/main/resources/application.properties (9)
1-1
: Application name is appropriately set to match the project context.
3-3
: Enabling virtual threads is a good practice for I/O-intensive applications.
4-4
: Enabling problem details for MVC is beneficial for debugging and error handling.
[APROVED]
6-6
: Verify the API key setting. If 'demo' is a placeholder, consider using an environment variable for security.
7-7
: Base URL is correctly set to point to the development server.
8-8
: Model setting for 'gpt-3.5-turbo' aligns with the application's requirements.
9-9
: Temperature setting is appropriately configured for controlling the model's response variability.
11-11
: Enabling embeddings is beneficial for enhancing the chatbot's contextual understanding.
13-13
: Configuring test containers to start in parallel is a good practice for speeding up integration tests.chatbot/chatbot-openai-springai/src/test/java/com/example/chatbot/TestChatbotOpenaiApplication.java (1)
10-23
: The test configuration class is well-structured with appropriate annotations and methods for setting up the test environment.chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/config/ChatConfig.java (2)
17-20
: ThechatMemory
method is correctly configured to use in-memory storage, suitable for development and testing environments.
22-30
: ThechatClient
method is well-configured with appropriate advisors, ensuring robust chat functionalities.chatbot/chatbot-openai-springai/src/main/java/com/example/chatbot/service/ChatbotService.java (1)
14-36
: TheChatbotService
class is well-structured with a clear separation of concerns, appropriate logging, and robust chat functionality.chatbot/chatbot-openai-springai/src/test/java/com/example/chatbot/ChatbotOpenaiApplicationTests.java (1)
33-36
: Setup method correctly configures RestAssured with the local server port.
@Test | ||
void chat() throws IOException { | ||
|
||
Response response = given().contentType(ContentType.JSON) | ||
.body(new AIChatRequest( | ||
"As a cricketer, how many centuries did Sachin Tendulkar scored adding up both One Day International (ODI) and Test centuries ?", | ||
"junitId")) | ||
.when() | ||
.post("/api/ai/chat") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.contentType(ContentType.JSON) | ||
.body("answer", containsString("100")) | ||
.log() | ||
.all(true) | ||
.extract() | ||
.response(); | ||
|
||
AIChatResponse aiChatResponse = objectMapper.readValue(response.asByteArray(), AIChatResponse.class); | ||
|
||
given().contentType(ContentType.JSON) | ||
.body(new AIChatRequest( | ||
"How many One Day International (ODI) centuries did he scored ?", | ||
aiChatResponse.conversationId())) | ||
.when() | ||
.post("/api/ai/chat") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.contentType(ContentType.JSON) | ||
.body("answer", containsString("49")) | ||
.log() | ||
.all(true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test cases for different chat scenarios could be refactored into a single parameterized test method to reduce redundancy and improve maintainability. Also, consider the potential brittleness of hardcoded expected responses in tests.
// Example of a parameterized test
@ParameterizedTest
@CsvSource({
"As a cricketer, how many centuries did Sachin Tendulkar scored adding up both One Day International (ODI) and Test centuries ?,junitId,100",
"How many One Day International (ODI) centuries did he scored ?,junitId,49"
})
void chat(String query, String conversationId, String expectedAnswer) throws IOException {
Response response = given().contentType(ContentType.JSON)
.body(new AIChatRequest(query, conversationId))
.when()
.post("/api/ai/chat")
.then()
.statusCode(HttpStatus.SC_OK)
.contentType(ContentType.JSON)
.body("answer", containsString(expectedAnswer))
.log()
.all(true)
.extract()
.response();
}
No description provided.