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 : expose endpoint to upload multiple documents #46

Merged
merged 4 commits into from
May 6, 2024

Conversation

rajadilipkolli
Copy link
Owner

No description provided.

Copy link
Contributor

coderabbitai bot commented May 6, 2024

Walkthrough

The recent updates across various Java files and properties in the Spring AI application primarily focus on enhancing data handling capabilities, refining AI service interactions, and updating model configurations. These changes streamline operations, improve data indexing and querying functionalities, and shift to using the more advanced llama2 model for both chat and embedding services.

Changes

File Path Change Summary
.../controller/DataIndexController.java Added methods for file uploads and data count retrieval.
.../service/AIChatService.java, .../service/DataIndexerService.java Adjusted logging levels, simplified query processes, and added document loading and counting functionalities.
.../resources/application.properties Updated AI model configurations from orca-mini to llama2 and adjusted other model parameters.
.../test/.../LlmRagWithSpringAiApplicationIntTest.java, .../test/.../TestLlmRagWithSpringAiApplication.java Enhanced test setups with new methods and updated Docker image references for testing, reflecting the shift to llama2.

Poem

🐇 "Hoppity hop, the code does swap,
🌟 From old to new, the changes grew.
📂 Files upload, data abode,
🚀 With llama's grace, we ace the space.
🌼 Spring forth, renew, as updates ensue!"


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.

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

@rajadilipkolli rajadilipkolli self-assigned this May 6, 2024
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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d6f4e17 and fc59df3.
Files selected for processing (7)
  • rag/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/config/AppConfig.java (1 hunks)
  • rag/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/controller/DataIndexController.java (1 hunks)
  • rag/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/service/AIChatService.java (2 hunks)
  • rag/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/service/DataIndexerService.java (1 hunks)
  • rag/rag-springai-ollama-llm/src/main/resources/application.properties (1 hunks)
  • rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/LlmRagWithSpringAiApplicationIntTest.java (5 hunks)
  • rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/TestLlmRagWithSpringAiApplication.java (1 hunks)
Additional comments not posted (13)
rag/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/config/AppConfig.java (1)

1-11: The configuration appears clean and well-implemented.

rag/rag-springai-ollama-llm/src/main/resources/application.properties (2)

6-9: Updated AI model and parameters align with the intended enhancements for chat functionality.


11-11: Model update for embedding functionality is consistent with the changes in chat model configuration.

rag/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/controller/DataIndexController.java (2)

20-28: The new file upload endpoint is well-implemented with proper exception handling.


31-34: The method for retrieving the count of indexed data is correctly implemented.

rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/TestLlmRagWithSpringAiApplication.java (1)

21-22: The update of the Docker image for testing aligns with the new AI model used in production settings.

rag/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/service/AIChatService.java (1)

45-46: Simplification of the similarity search method enhances clarity and maintainability.

rag/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/service/DataIndexerService.java (2)

29-53: The method for loading and indexing documents is robust, handling multiple document types and logging appropriately.


56-58: The method for counting documents in the vector store is implemented efficiently.

rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/LlmRagWithSpringAiApplicationIntTest.java (4)

36-43: The test for uploading PDF content is correctly implemented and verifies the endpoint's functionality.


49-53: The test for handling chat requests is well-implemented, ensuring the chat functionality responds as expected.


Line range hint 64-82: Tests for handling edge cases in chat requests (empty and long queries) are thorough and ensure robust error handling.


101-101: The test for special characters in chat queries effectively checks for input validation.

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: 2

Out of diff range and nitpick comments (2)
rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/LlmRagWithSpringAiApplicationIntTest.java (2)

12-13: Consider using Path over File for better performance and flexibility.

Java's Path API, part of the NIO package, provides more modern and flexible file operations compared to the older File class. It's recommended to use Path for new developments.


Line range hint 106-125: Consider testing for other types of long queries.

Testing with a single repeated character is a good start, but consider adding tests with more complex long strings, such as those including spaces or special characters. Would you like assistance in generating these additional test cases?

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between fc59df3 and d8a5350.
Files selected for processing (2)
  • rag/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/controller/DataIndexController.java (1 hunks)
  • rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/LlmRagWithSpringAiApplicationIntTest.java (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • rag/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/controller/DataIndexController.java
Additional comments not posted (4)
rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/LlmRagWithSpringAiApplicationIntTest.java (4)

36-45: Ensure the PDF file path is correctly referenced and accessible.

Verification successful

The shell script output confirms the existence of the PDF file "Rohit_Gurunath_Sharma.pdf" within the repository, specifically located in the src/main/resources directory of the rag-springai-ollama-llm module. This location is a standard directory for resources in a Java project, which are typically accessible via the classpath.

Given this information, the PDF file path referenced in the test method uploadPdfContent() should be correctly accessible if the method getFile() appropriately resolves paths to the classpath resources. The review comment's concern about verifying the PDF file path's correctness and accessibility is addressed by the script's output showing the file's presence in a standard resource directory.

Therefore, I will conclude that the file path is correctly referenced and accessible in the context of the test environment.


PDF File Path Verified and Accessible

The PDF file "Rohit_Gurunath_Sharma.pdf" used in the test uploadPdfContent() is correctly placed in the resources directory and should be accessible via the classpath. This setup aligns with standard Java project practices for handling resources.

  • File Location: src/main/resources/Rohit_Gurunath_Sharma.pdf
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the existence of the PDF file used in tests.

# Test: Check if the file exists in the classpath.
fd --type file 'Rohit_Gurunath_Sharma.pdf' --exec ls -l {}

Length of output: 175


47-57: LGTM! Good use of REST Assured for API testing.

This test method effectively checks the count of uploaded documents, ensuring the endpoint behaves as expected under normal conditions.


Line range hint 88-106: Excellent coverage of edge cases for chat functionality.

This test method effectively handles an empty query scenario, ensuring the system responds with appropriate error messages and status codes.


Line range hint 125-142: Good validation of special characters in queries.

This test ensures that the system correctly handles queries with special characters, returning appropriate error messages and status codes.

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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d8a5350 and 4214972.
Files selected for processing (1)
  • rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/LlmRagWithSpringAiApplicationIntTest.java (7 hunks)
Files not reviewed due to errors (1)
  • rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/LlmRagWithSpringAiApplicationIntTest.java (no review received)

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: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4214972 and 89e81fa.
Files selected for processing (1)
  • rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/LlmRagWithSpringAiApplicationIntTest.java (7 hunks)
Additional comments not posted (7)
rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/LlmRagWithSpringAiApplicationIntTest.java (7)

52-62: LGTM! The test for counting uploaded PDF content is correctly implemented.


Line range hint 64-89: LGTM! The AI chat functionality tests are well-implemented and cover basic query scenarios.


Line range hint 92-138: LGTM! The tests for handling empty and special character queries in AI chat are correctly implemented.


164-178: LGTM! The test for unsupported content types is correctly implemented.


180-197: LGTM! The test for missing required fields in AI chat requests is correctly implemented.


199-213: LGTM! The test for handling invalid JSON structures in AI chat requests is correctly implemented.


215-217: Ensure the getPath method handles exceptions properly.

Comment on lines +42 to +50
void uploadPdfContent() throws IOException, URISyntaxException {
given().multiPart("file", getPath("/Rohit_Gurunath_Sharma.pdf").toFile())
.when()
.post("/api/data/v1/upload")
.then()
.statusCode(200)
.log()
.all();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The verification process has shown that the file "/Rohit_Gurunath_Sharma.pdf" does not exist in the 'src/test/resources' directory, which was assumed to be the correct location based on the context of a typical Java project structure. This suggests that there might be an issue with how the file path is handled or documented in the test setup. It is recommended to review the implementation of the getPath method to ensure it points to the correct location and that the necessary test files are properly placed in the project structure.

  • Review the implementation of the getPath method to confirm the intended file path.
  • Ensure that the file "/Rohit_Gurunath_Sharma.pdf" is correctly placed in the project structure as expected by the test.
Analysis chain

Ensure the file path in getPath method is correctly handled.


The verification script intended to check the existence of the file specified in the getPath method failed because the Java command could not be executed in the script's environment. This means we haven't yet verified whether the file path is correctly handled in the code.

To proceed, I recommend running a revised script that doesn't rely on executing Java, but instead directly checks the file system based on expected outcomes from the getPath method, if such expected outcomes can be inferred from the codebase or documentation.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the file path provided in the `getPath` method is correctly handled and accessible.

# Test: Check if the file exists at the specified path.
if [ -f "$(java -jar rag/rag-springai-ollama-llm/src/test/java/com/learning/ai/llmragwithspringai/LlmRagWithSpringAiApplicationIntTest.java getPath /Rohit_Gurunath_Sharma.pdf)" ]; then
  echo "File exists."
else
  echo "File does not exist."
fi

Length of output: 305



Script:

#!/bin/bash
# Description: Check if the file path "/Rohit_Gurunath_Sharma.pdf" exists in the expected directory.

# Assuming the file should be located in a 'resources' directory under 'src/test/java'
if [ -f "src/test/resources/Rohit_Gurunath_Sharma.pdf" ]; then
  echo "File exists."
else
  echo "File does not exist."
fi

Length of output: 108

Comment on lines +148 to +162
@Test
@Order(114)
void testNullRequestBody() {
given().contentType(ContentType.JSON)
.body(Optional.empty())
.when()
.post("/api/ai/chat")
.then()
.statusCode(400)
.header(HttpHeaders.CONTENT_TYPE, is(MediaType.APPLICATION_PROBLEM_JSON_VALUE))
.body("detail", is("Failed to read request"))
.body("instance", is("/api/ai/chat"))
.body("title", is("Bad Request"))
.log();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test checks for null request bodies in AI chat. Consider adding a more descriptive error message.

- .body("detail", is("Failed to read request"))
+ .body("detail", is("Request body cannot be null or empty"))

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
@Test
@Order(114)
void testNullRequestBody() {
given().contentType(ContentType.JSON)
.body(Optional.empty())
.when()
.post("/api/ai/chat")
.then()
.statusCode(400)
.header(HttpHeaders.CONTENT_TYPE, is(MediaType.APPLICATION_PROBLEM_JSON_VALUE))
.body("detail", is("Failed to read request"))
.body("instance", is("/api/ai/chat"))
.body("title", is("Bad Request"))
.log();
}
@Test
@Order(114)
void testNullRequestBody() {
given().contentType(ContentType.JSON)
.body(Optional.empty())
.when()
.post("/api/ai/chat")
.then()
.statusCode(400)
.header(HttpHeaders.CONTENT_TYPE, is(MediaType.APPLICATION_PROBLEM_JSON_VALUE))
.body("detail", is("Request body cannot be null or empty"))
.body("instance", is("/api/ai/chat"))
.body("title", is("Bad Request"))
.log();
}

@rajadilipkolli rajadilipkolli merged commit fefbb7f into main May 6, 2024
2 checks passed
@rajadilipkolli rajadilipkolli deleted the expose-endpoint branch May 6, 2024 11:18
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