skyl / corpora

Corpora is a self-building corpus that can help build other arbitrary corpora
GNU Affero General Public License v3.0
2 stars 0 forks source link

feat(rs/core/corpora_cli): chat the corpus #58

Closed skyl closed 3 days ago

skyl commented 3 days ago

PR Type

enhancement, tests


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
8 files
corpus.py
Add chat endpoint and integrate LLM for corpus interaction

py/packages/corpora/routers/corpus.py
  • Added a new endpoint for chatting with the corpus.
  • Modified the chat system message for more creativity.
  • Integrated LLM provider for text completion.
  • +52/-56 
    corpus_api.py
    Update chat API to include 404 response type                         

    py/packages/corpora_client/api/corpus_api.py - Added 404 response type to chat API.
    +3/-0     
    configuration.py
    Add TypedDicts for auth settings and enhance type annotations

    py/packages/corpora_client/configuration.py
  • Added new TypedDicts for various authentication settings.
  • Enhanced type annotations for configuration methods.
  • +149/-38
    chat.rs
    Implement chat command in CLI with corpora client integration

    rs/core/corpora_cli/src/commands/chat.rs
  • Implemented chat command for CLI.
  • Integrated with corpora client for message handling.
  • +65/-0   
    mod.rs
    Add chat command to CLI subcommands                                           

    rs/core/corpora_cli/src/commands/mod.rs - Added chat command to CLI subcommands.
    +3/-0     
    config.rs
    Add relative path field to CorporaConfig                                 

    rs/core/corpora_cli/src/context/config.rs - Added relative path field to CorporaConfig.
    +9/-3     
    main.rs
    Integrate chat command into main CLI execution                     

    rs/core/corpora_cli/src/main.rs - Integrated chat command into main CLI execution.
    +1/-0     
    corpus_api.rs
    Add 404 status handling for chat errors                                   

    rs/core/corpora_client/src/apis/corpus_api.rs - Added 404 status handling for chat errors.
    +1/-0     
    Miscellaneous
    1 files
    genall.sh
    Add echo statements for generation steps                                 

    genall.sh - Added echo statements for generation steps.
    +2/-0     
    Configuration changes
    1 files
    openapitools.json
    Add OpenAPI configuration file                                                     

    openapitools.json - Added new OpenAPI configuration file.
    +7/-0     
    Dependencies
    2 files
    openapitools.json
    Update OpenAPI generator version to 7.10.0                             

    py/openapitools.json - Updated OpenAPI generator version to 7.10.0.
    +2/-2     
    openapitools.json
    Update OpenAPI generator version to 7.10.0                             

    rs/openapitools.json - Updated OpenAPI generator version to 7.10.0.
    +1/-1     
    Documentation
    2 files
    README.md
    Update Python version requirement and OpenAPI generator version

    py/packages/corpora_client/README.md
  • Updated Python version requirement to 3.8+.
  • Updated OpenAPI generator version in documentation.
  • +2/-2     
    CorpusApi.md
    Document 404 response for chat API                                             

    py/packages/corpora_client/docs/CorpusApi.md - Documented 404 response for chat API.
    +1/-0     

    ๐Ÿ’ก PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    github-actions[bot] commented 3 days ago

    PR Reviewer Guide ๐Ÿ”

    Here are some key observations to aid the review process:

    โฑ๏ธ Estimated effort to review: 4 ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ตโšช
    ๐Ÿงช No relevant tests
    ๐Ÿ”’ No security concerns identified
    โšก Recommended focus areas for review

    Code Smell
    The `print` statement on line 79 should be removed or replaced with proper logging to avoid unnecessary console output in production. Error Handling
    The `unwrap` method is used on line 18, which can cause the program to panic if an error occurs. Consider using proper error handling to manage potential failures gracefully. Error Handling
    The `unwrap_or_default` method is used on lines 28-31. While it provides a default value, it may hide errors that should be addressed. Consider logging or handling errors explicitly.
    github-actions[bot] commented 3 days ago

    PR Code Suggestions โœจ

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add a check to handle the case where the corpus is not found to prevent runtime errors ___ **Ensure that the corpus object is not None after attempting to retrieve it with aget,
    and handle the case where the corpus is not found to prevent potential runtime
    errors.** [py/packages/corpora/routers/corpus.py [69]](https://github.com/skyl/corpora/pull/58/files#diff-3ac4611171c3ba2b1e471a17f85e949a5df6e835391d39367db05286216d1762R69-R69) ```diff corpus = await Corpus.objects.aget(id=payload.corpus_id) +if corpus is None: + raise HttpError(404, "Corpus not found.") ```
    Suggestion importance[1-10]: 9 Why: The suggestion addresses a critical issue by adding a check to handle the case where the corpus is not found, preventing potential runtime errors. This enhances the robustness of the code by ensuring that a 404 error is raised if the corpus is not found, which is a significant improvement.
    9
    Add error handling for file reading operations to prevent panics if files are missing or unreadable ___ **Handle potential errors when reading files with fs::read_to_string to prevent the
    program from panicking if the files are missing or unreadable.** [rs/core/corpora_cli/src/commands/chat.rs [28-32]](https://github.com/skyl/corpora/pull/58/files#diff-60cfd986b6359a6be930cd43a2a5d02592c585dd6f79616350711570e6b8002fR28-R32) ```diff -let voice = fs::read_to_string(root_path.join(".corpora/VOICE.md")).unwrap_or_default(); -let purpose = fs::read_to_string(root_path.join(".corpora/PURPOSE.md")).unwrap_or_default(); -let structure = fs::read_to_string(root_path.join(".corpora/STRUCTURE.md")).unwrap_or_default(); +let voice = fs::read_to_string(root_path.join(".corpora/VOICE.md")).unwrap_or_else(|err| { + ctx.error(&format!("Failed to read VOICE.md: {:?}", err)); + String::new() +}); +let purpose = fs::read_to_string(root_path.join(".corpora/PURPOSE.md")).unwrap_or_else(|err| { + ctx.error(&format!("Failed to read PURPOSE.md: {:?}", err)); + String::new() +}); +let structure = fs::read_to_string(root_path.join(".corpora/STRUCTURE.md")).unwrap_or_else(|err| { + ctx.error(&format!("Failed to read STRUCTURE.md: {:?}", err)); + String::new() +}); ```
    Suggestion importance[1-10]: 8 Why: This suggestion improves the robustness of the Rust code by adding error handling for file reading operations. It prevents the program from panicking if the files are missing or unreadable, which is crucial for maintaining stability and providing meaningful error messages.
    8