Skip to content

Commit

Permalink
Some improvements (#1882)
Browse files Browse the repository at this point in the history
* Update main.py

* Update main.py

Type Annotations and Descriptions: Added Field descriptions for better API documentation and validation.
Improved Logging: Enhanced logging to include more context and error tracebacks for easier debugging.
Input Validation: Used List from typing to enforce type checking and improve clarity.
Response Model: Ensured the response model is clearly defined with descriptions.
Exception Handling: Enhanced error handling to log the stack trace.
Code Formatting and Comments: Improved overall code formatting and added comments for clarity.

This revised version provides better maintainability and clarity for users of the API.

* Update collections.py

Utility Function: Introduced execute_collection_command to handle API calls, reducing code repetition and improving readability.
Type Hints: Added type hints for function arguments and return types, enhancing code clarity and allowing for better static analysis.
Error Messages: Improved error messages to specify the type of exception encountered, which can be useful for debugging.
Documentation: Updated docstrings for more clarity on what each command does.
Optional Parameters: Set default values for optional parameters in type hints.

This structure makes the code easier to maintain and understand while providing a clearer interface for handling API interactions.

* Update config.py

Type Hints: Added type hints to functions for better clarity and type checking.
Improved Docstrings: Enhanced the docstrings for clarity on what each method does.
Code Structure: Improved the organization of the code, particularly in the view function, to enhance readability.
Use of Constants: Used constants for repeated strings to avoid hardcoding, allowing easier adjustments in the future.
Console Output: Kept feedback messages concise and clear for better user experience.

* Update conversations.py

Error Messages: Improved the clarity and specificity of error messages to indicate which operation failed and with which ID.
Default Values: Clarified the purpose of the offset and limit options in the list and list_users commands.
Response Handling: Used response.get("results", []) to safely handle cases where the response may not contain the expected "results" key.
Consistent Formatting: Ensured consistent formatting in echo messages across different commands.
Improved Documentation: Enhanced the command descriptions for better understanding of their functionality.

These enhancements should improve the usability and maintainability of the CLI.

* Update database.py

Function check_connection_and_run: This function encapsulates the logic for checking the database connection and running the Alembic command, reducing duplication across your command functions.
Improved Exit Handling: All commands now return their results to handle exit codes more consistently.
Type Annotations: Each async command function is annotated with types for clarity.
User Prompts: The confirmation prompt for downgrades is improved to inform the user of the consequences of their action.

This refactored code should be cleaner, easier to maintain, and more user-friendly.

* Update documents.py

Modularization: Created helper functions like create_document_table, create_metadata_table, create_chunk_table, and create_collection_table to reduce code duplication and improve readability.
Error Handling: Enhanced error messages for better visibility and understanding of errors.
Use of Context Managers: Use of with statements for file handling, ensuring that files are properly closed.
Type Annotations: Ensured type annotations are consistent throughout the code, improving code clarity.
General Cleanup: Improved formatting, added comments for clarity, and ensured consistent usage of string formatting.

* Update graphs.py

Helper Functions: Added handle_response and handle_error functions to reduce code duplication and improve readability.
Consistent Success Messages: Each command now has a consistent success message upon successful execution.
Improved Error Handling: Centralized error handling simplifies the main command logic and enhances readability.
Comments: Added comments to provide context for the structure and purpose of functions.

* Update indices.py

Improved Error Messages: Specific prefixes for R2R errors help in distinguishing them from unexpected errors.
Check for Empty Results: Added a check in the list command to inform the user if no indices are found.
Type Annotations: Added type annotations for method parameters to improve readability and help with type checking.
Functionality in Delete Command: It seems your delete command was incorrectly retrieving instead of deleting. This has been corrected assuming a delete method exists in the client.indices object.
User Feedback: Added a success message for the delete operation to inform the user that the operation was completed successfully.

With these enhancements, the code is not only cleaner but also user-friendly, providing better feedback and handling various scenarios more gracefully.

* Update prompts.py

Logging: Added logging to track the flow of commands and errors. This can help in debugging and maintaining the code.
Type Hints: Added type hints for function parameters and return types for better clarity and tooling support.
Default Values and Help Text: Added help text for options in the retrieve command to provide more context to the user.
Use of get Method: Used .get() to handle potential KeyError when accessing the results key in the response dictionary in the list command.
Error Messages: Simplified the error messages for consistency and clarity.

These improvements should make the code more maintainable, user-friendly, and easier to debug.

* Update retrieval.py

Readability: Improved formatting and added comments for clarity.
Consistency: Maintained consistent naming conventions and structure across both command functions.
Error Handling: Improved error messages for better clarity.
Documentation: Enhanced docstrings for commands and parameters to provide better context.
Code Duplication: Reduced redundancy in the handling of search settings between the search and rag commands.

* Update system.py

Type Hints: Added type hints to function signatures for clarity.
Improved Error Messages: Enhanced error messages to be more descriptive, indicating the operation that failed.
Code Organization: Organized imports and structured the code for readability.
Consolidated Logic: Simplified condition checks where possible.
Consistent Logging: Ensured consistent logging of messages to assist with debugging and user feedback.
Function Documentation: Kept docstrings consistent and informative for each function.

* Update users.py

Improved Error Messages: Each command now provides more context in error messages, indicating which operation failed and why.
Use of get Method: When accessing dictionary keys (like response["results"]), switched to using .get() to avoid potential KeyError.
Documentation: Enhanced docstrings for each command to provide clearer explanations.
Type Hinting: Ensured all parameters have clear type hints for better readability and maintainability.
Code Consistency: Maintained consistent formatting and structure throughout the code for readability.
UUID Handling: The UUID conversion is done in a more concise way.
Default Values: Clearly stated default values in the help message for options.

* Bump nanoid in /js/sdk in the npm_and_yarn group across 1 directory

Bumps the npm_and_yarn group with 1 update in the /js/sdk directory: [nanoid](https://github.com/ai/nanoid).


Updates `nanoid` from 3.3.7 to 3.3.8
- [Release notes](https://github.com/ai/nanoid/releases)
- [Changelog](https://github.com/ai/nanoid/blob/main/CHANGELOG.md)
- [Commits](ai/nanoid@3.3.7...3.3.8)

---
updated-dependencies:
- dependency-name: nanoid
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump python-multipart in /py in the pip group across 1 directory

Bumps the pip group with 1 update in the /py directory: [python-multipart](https://github.com/Kludex/python-multipart).


Updates `python-multipart` from 0.0.9 to 0.0.18
- [Release notes](https://github.com/Kludex/python-multipart/releases)
- [Changelog](https://github.com/Kludex/python-multipart/blob/master/CHANGELOG.md)
- [Commits](Kludex/python-multipart@0.0.9...0.0.18)

---
updated-dependencies:
- dependency-name: python-multipart
  dependency-type: direct:production
  dependency-group: pip
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump gunicorn in /py in the pip group across 1 directory

Bumps the pip group with 1 update in the /py directory: [gunicorn](https://github.com/benoitc/gunicorn).


Updates `gunicorn` from 21.2.0 to 22.0.0
- [Release notes](https://github.com/benoitc/gunicorn/releases)
- [Commits](benoitc/gunicorn@21.2.0...22.0.0)

---
updated-dependencies:
- dependency-name: gunicorn
  dependency-type: direct:production
  dependency-group: pip
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update .pre-commit-config.yaml

* Pre-commit

* Remove venv directory from tracking

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Nolan Tremelling <[email protected]>
  • Loading branch information
3 people authored Jan 30, 2025
1 parent 9c40ca0 commit 47ff83f
Show file tree
Hide file tree
Showing 17 changed files with 882 additions and 1,353 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down Expand Up @@ -49,3 +49,4 @@ repos:
language: system
types: [python]
pass_filenames: false

173 changes: 135 additions & 38 deletions js/sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 47ff83f

Please sign in to comment.