Skip to content
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

Merged
merged 9 commits into from
Jun 13, 2024
Merged

Conversation

rajadilipkolli
Copy link
Owner

No description provided.

@rajadilipkolli rajadilipkolli self-assigned this May 27, 2024
Copy link
Contributor

coderabbitai bot commented May 27, 2024

Walkthrough

The 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

File Path Change Summary
.chatbot/chatbot-ollama-.../ChatbotOllamaApplicationTests.java Simplified exception handling in chat() method signatures.
.chatbot/chatbot-openai-.../.gitignore Updated to exclude various IDE, build, configuration files, and directories.
.chatbot/chatbot-openai-...maven-wrapper.properties, mvnw, mvnw.cmd Introduced licensing info, specified Maven wrapper version; set up batch scripts for Maven installation.
.chatbot/chatbot-openai-.../ReadMe.md Added sequence diagram for interaction flow with the Vector Store in the chatbot system.
.chatbot/chatbot-openai-.../ChatbotOpenaiApplication.java New Spring Boot application setup for the OpenAI chatbot.
.chatbot/chatbot-openai-.../config/ChatConfig.java Added VectorStore parameter to chatClient method and configuration for chat memory and client setup.
.chatbot/chatbot-openai-.../config/LoggingConfig.java Added methods for logging HTTP requests/responses.
.chatbot/chatbot-openai-.../config/SwaggerConfig.java Included Swagger annotations for OpenAPI definition and server configuration.
.chatbot/chatbot-openai-.../controller/ChatbotController.java New REST controller for handling AI chat requests.
.chatbot/chatbot-openai-.../model/request/AIChatRequest.java Introduced AIChatRequest Java record class.
.chatbot/chatbot-openai-.../model/response/AIChatResponse.java Introduced AIChatResponse Java record class.
.chatbot/chatbot-openai-.../service/ChatbotService.java Added a new ChatbotService class with a chat method to interact with ChatClient.
.chatbot/chatbot-openai-.../resources/application.properties Introduced configuration settings for the OpenAI API.
.chatbot/chatbot-openai-.../ChatbotOpenaiApplicationTests.java Introduced test cases for chatbot interactions with cricket-related questions.
.chatbot/chatbot-openai-.../TestChatbotOpenaiApplication.java Introduced a test configuration using Spring Boot and MilvusContainer.

Poem

In the realm of chatbots, a change did start,
Simplified exceptions, a work of art.
Configs updated, Maven on task,
OpenAI's magic in Spring Boot's mask.
Logging and Swagger, all now entwined,
In the dance of code, a future defined.
Cheers to the code, in harmony it sings,
Our chatbot now flies on renewed wings! 🐰🚀✨


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 5af5bde and 2273a75.
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.

Comment on lines 35 to 73
@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);
}
Copy link
Contributor

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


Copy link
Contributor

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.

Suggested change

ChatbotService-->>ChatbotController: response
ChatbotController-->>User: response

```
Copy link
Contributor

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.

@rajadilipkolli rajadilipkolli merged commit 33b1f57 into main Jun 13, 2024
3 of 4 checks passed
@rajadilipkolli rajadilipkolli deleted the chatbot-openai branch June 13, 2024 16:21
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between 2273a75 and 6bd5e90.

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: The chatMemory method is correctly configured to use in-memory storage, suitable for development and testing environments.


22-30: The chatClient 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: The ChatbotService 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.

Comment on lines +38 to +70
@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);
}
Copy link
Contributor

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();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant