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

Add Example for Spring AI #114

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Add Example for Spring AI #114

wants to merge 5 commits into from

Conversation

rashidi
Copy link
Owner

@rashidi rashidi commented Feb 22, 2024

Summary by CodeRabbit

  • New Features
    • Introduced an AI chat feature that integrates with Spring Boot for retrieving and displaying historical information based on country and year.
    • Added functionality to exclude IDE-specific files and directories from version control.
    • Set up project configuration for Java compatibility and Spring AI integration with OpenAI.
  • Documentation
    • Added a root project name in the settings for better project management.
  • Tests
    • Implemented tests for the application context and historical data retrieval functionality.

@rashidi rashidi added the enhancement New feature or request label Feb 22, 2024
Copy link

coderabbitai bot commented Feb 22, 2024

Important

Auto Review Skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

This update enriches a Java-based AI project with Spring Boot, emphasizing AI interactions and historical data retrieval. It orchestrates the project environment, establishes dependencies for Spring AI and web development, and introduces classes for application execution and chat history management. Testing ensures the functionality of the application components, while configuration settings fine-tune the AI chat feature for an enhanced user experience.

Changes

File Path Change Summary
ai/.gitignore
ai/build.gradle
ai/settings.gradle
Introduces rules for excluding IDE-specific files, configures Java project with Spring Boot and dependencies, and sets project name.
ai/src/main/.../AiApplication.java
ai/src/main/.../history/ChatHistoryRepository.java
ai/src/main/.../history/History.java
ai/src/main/.../history/HistoryRepository.java
Adds application and history management classes.
ai/src/test/.../AiApplicationTests.java
ai/src/test/.../history/HistoryRepositoryTests.java
Provides tests for application context and history retrieval.
ai/src/main/resources/application.properties Configures settings for the AI chat feature.

🐰✨
To the code we hop and leap,
Through history's secrets, we delve deep.
With Spring in our step, we craft and create,
A garden of data, opening the gate.
🌼📚🌟
In each line of code, a story to tell,
With AI and Spring, we weave our spell.

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4f71a5f and 962f61b.
Files selected for processing (10)
  • ai/.gitignore (1 hunks)
  • ai/build.gradle (1 hunks)
  • ai/settings.gradle (1 hunks)
  • ai/src/main/java/zin/rashidi/boot/ai/AiApplication.java (1 hunks)
  • ai/src/main/java/zin/rashidi/boot/ai/history/ChatHistoryRepository.java (1 hunks)
  • ai/src/main/java/zin/rashidi/boot/ai/history/History.java (1 hunks)
  • ai/src/main/java/zin/rashidi/boot/ai/history/HistoryRepository.java (1 hunks)
  • ai/src/main/resources/application.properties (1 hunks)
  • ai/src/test/java/zin/rashidi/boot/ai/AiApplicationTests.java (1 hunks)
  • ai/src/test/java/zin/rashidi/boot/ai/history/HistoryRepositoryTests.java (1 hunks)
Files skipped from review due to trivial changes (3)
  • ai/.gitignore
  • ai/settings.gradle
  • ai/src/main/java/zin/rashidi/boot/ai/AiApplication.java
Additional comments: 7
ai/src/main/java/zin/rashidi/boot/ai/history/History.java (1)
  • 1-9: The History record is well-defined and follows Java best practices for immutable data structures. It's a concise way to encapsulate historical event data.
ai/src/main/resources/application.properties (1)
  • 1-4: The configuration for the Spring AI OpenAI chat options is correctly set up, with sensible defaults for the model, temperature, top-p, and response format. This setup is crucial for tailoring the AI's behavior and response format.
ai/src/main/java/zin/rashidi/boot/ai/history/HistoryRepository.java (1)
  • 1-12: The HistoryRepository interface is well-designed, with a clear and focused responsibility. The method findByCountryAndYear is appropriately named and uses java.time.Year, which is a good choice for handling years.
ai/src/test/java/zin/rashidi/boot/ai/AiApplicationTests.java (1)
  • 1-13: The AiApplicationTests class is correctly set up for Spring Boot testing, ensuring the application context loads successfully. This is a standard and essential test for Spring Boot applications.
ai/build.gradle (1)
  • 1-34: The build.gradle file is well-configured for a Spring Boot project, including the necessary plugins, repositories, and dependencies for Spring AI and OpenAI integration. However, consider verifying the sourceCompatibility set to '21' with the development team to ensure compatibility with their environments.
ai/src/test/java/zin/rashidi/boot/ai/history/HistoryRepositoryTests.java (1)
  • 1-44: The HistoryRepositoryTests class provides thorough and well-structured tests for the HistoryRepository functionality, using clear descriptions and appropriate assertions. These tests effectively validate the retrieval of historical information based on country and year.
ai/src/main/java/zin/rashidi/boot/ai/history/ChatHistoryRepository.java (1)
  • 1-60: The ChatHistoryRepository class is well-implemented, effectively using Spring AI's ChatClient, EmbeddingClient, and an ObjectMapper to process historical chat data. The approach to constructing messages and parsing the AI's response is innovative and well-crafted. However, consider adding error handling for the external calls to AI services to ensure robustness.

Copy link

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 962f61b and 43020fc.
Files selected for processing (1)
  • settings.gradle (1 hunks)
Additional comments: 1
settings.gradle (1)
  • 17-17: The addition of the ai module to the settings.gradle file aligns with the PR's objectives to integrate AI capabilities into the Spring Boot application. Ensure that the module name ai aligns with any existing project naming conventions and does not conflict with other modules in the project.

@rashidi rashidi marked this pull request as draft February 22, 2024 13:29
This commit introduces a whole new AI application along with a 'history' feature. The AI application includes necessary initial files including '.gitignore', 'build.gradle', 'settings.gradle', and 'application.properties'. The 'history' feature has an implementation through 'HistoryRepository', 'ChatHistoryRepository' and tests under 'HistoryRepositoryTests'.
Removed the EmbeddingClient from ChatHistoryRepository. This involved removing the EmbeddingClient field, its use in the constructor, and its use in creating a response. This change simplified the ChatHistoryRepository class by decoupling it from direct use of the EmbeddingClient.
New environment variable SPRING_AI_OPENAI_API_KEY is added in Github gradle workflow file to support running the Spring AI model. It is set with the same secret as LANGCHAIN4J_CHAT_MODEL_OPENAI_API_KEY for now.
The Spring Boot version in the build.gradle file has been updated from 3.2.2 to 3.2.3. This update keeps the build configuration synchronized with the latest stable version of the framework.
Copy link

sonarcloud bot commented Feb 24, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

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

Successfully merging this pull request may close these issues.

1 participant