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

Remove strict validate and make claude model available #372

Merged
merged 11 commits into from
Apr 13, 2024
Merged

Remove strict validate and make claude model available #372

merged 11 commits into from
Apr 13, 2024

Conversation

sudoskys
Copy link
Member

@sudoskys sudoskys commented Apr 13, 2024

Summary by CodeRabbit

  • New Features

    • Added a new Cost class for detailed cost management.
    • Introduced a new field driver in UserConfig class for enhanced configuration.
    • Updated Python version requirements and project description in pyproject.toml.
  • Bug Fixes

    • Simplified error handling in SDK adapter methods to improve reliability.
    • Enhanced validation logic in Driver class to ensure endpoint accuracy.
  • Refactor

    • Major code clean-up across multiple modules for improved readability and maintainability.
    • Refactored UserCost and LlmConfig classes to streamline configuration settings.
    • Removed deprecated methods and unused imports to optimize code performance.
  • Documentation

    • Updated method signatures in CostControl class to reflect current functionalities.

This commit adds tests for error handling in pydantic models. It includes
examples of missing fields and their corresponding validation errors.
- Corrected indentation in schema.py
- Removed unnecessary code in schema.py
- Removed unnecessary code in __init__.py
- Deprecated SystemPrompt class
- Added SingleModel to SCHEMA_GROUP
- Updated Openai imports and definitions
- Remove id, object, and created properties
- Remove result_type method
- Remove redundant property validations
- Remove deprecated functions and function_call properties
- Simplify model_config initialization
- Clean up comments and unused imports
- Corrected indentation for 'if' statements
- Adjusted parameter spacing for 'async def' functions
- Aligned parameter spacing for 'classmethod' functions
- Removed unnecessary condition for 'add_property'
- Updated 'parse_from_pydantic' method signature
- Modified 'request_final' method signature
- Fixed file extension check for images
- Improved 'generate_short_md5' function clarity
- Corrected indentation for 'if' statements
- Adjusted parameter spacing for 'async def' functions
- Aligned parameter spacing for 'classmethod' functions
- Removed unnecessary condition for 'add_property'
- Updated 'parse_from_pydantic' method signature
- Modified 'request_final' method signature
- Fixed file extension check for images
- Improved 'generate_short_md5' function clarity
Copy link
Contributor

coderabbitai bot commented Apr 13, 2024

Walkthrough

The recent updates focus on enhancing the codebase across various modules for improved readability and consistency. Changes include introducing new classes for cost management, refining method signatures, and removing deprecated elements. Additionally, there are adjustments to error handling and API configurations, aligning with modern Python standards. The version bump in pyproject.toml reflects these cumulative enhancements.

Changes

File Path Change Summary
.../user/__init__.py Removed unused imports, updated method signatures in CostControl.
.../user/schema.py, .../llm_task.py Added Cost class, refactored UserCost, updated imports and method adjustments in middleware related to cost handling.
.../receiver_client.py Code refactoring for clarity and consistency.
.../sdk/adapter.py, .../sdk/endpoint/schema.py Simplified methods, improved error handling by removing or adjusting exception logic.
.../sdk/endpoint/__init__.py, .../sdk/endpoint/openai/__init__.py, .../sdk/endpoint/tee.py Streamlined imports, class attributes, and methods. Enhanced validation and configuration settings.
.../sdk/schema.py Simplified logic in request_final method.
pyproject.toml Updated version and Python compatibility, modified description.
tests/pydantic_error.py Demonstrated error handling in Pydantic model instantiation.

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.

@sudoskys sudoskys merged commit 3c3709c into main Apr 13, 2024
3 checks passed
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: 4

@@ -3,11 +3,11 @@
# @Author : sudoskys
# @File : base.py
# @Software: PyCharm
from pydantic import field_validator, ConfigDict, model_validator
from pydantic import field_validator, ConfigDict
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider removing unused import field_validator.

- from pydantic import field_validator, ConfigDict
+ from pydantic import ConfigDict

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
from pydantic import field_validator, ConfigDict
from pydantic import ConfigDict


__version__ = "0.0.1"

from typing import Union, List, Optional, Literal, Type
from typing import Union, List, Optional, Literal
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unused imports to clean up the code.

- from typing import Union, List, Optional, Literal

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
from typing import Union, List, Optional, Literal

Comment on lines +176 to +197
# Do not check token limit, 没有意义
# 返回请求
headers = {
"User-Agent": "Mozilla/5.0",
"Authorization": f"Bearer {self._config.api_key}",
"api-key": f"{self._config.api_key}",
"Authorization": f"Bearer {self.config.api_key}",
"api-key": f"{self.config.api_key}",
}
if self._config.org_id:
headers["Openai-Organization"] = self._config.org_id
if self.config.org_id:
headers["Openai-Organization"] = self.config.org_id
try:
logger.debug(f"[Openai request] {self.create_params()}")
_response = await request(
method="POST",
url=self._config.endpoint,
url=self.config.endpoint,
data=self.create_params(),
headers=headers,
proxy=self.proxy_address(),
json_body=True,
)
assert _response, ValidationError("response is empty")
logger.debug(f"[Openai response] {_response}")
return_result = OpenaiResult.model_validate(_response).ack()
return_result = OpenaiResult.model_validate(_response)
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor the create method to separate concerns for better readability and maintainability.

The method is doing too much: handling API requests, setting headers, and error handling. Consider breaking it down into smaller methods.

@@ -4,11 +4,10 @@
# @File : __init__.py
# @Software: PyCharm


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 scripts have successfully identified references to both Driver from the tee module and get_tokenizer from the tokenizer module in various parts of the project. This indicates that the removal of these imports from the llmkira/sdk/endpoint/__init__.py file could potentially lead to issues unless these dependencies are managed differently in the updated architecture.

Here are the findings:

  1. The Driver class is still being used in llmkira/sdk/endpoint/schema.py, llmkira/sdk/endpoint/openai/__init__.py, and an external script in docs/test_script/note_openai_req.py.
  2. The function get_tokenizer is still being used in llmkira/schema.py and is defined in llmkira/sdk/endpoint/tokenizer.py.

Given these references, it is crucial to ensure that the removal of imports from the __init__.py file does not break these dependencies. This might require a deeper look into how these modules are imported and used across the project post-removal.

Analysis chain

Verify removal of Driver and get_tokenizer imports.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to `Driver` from `tee` and `get_tokenizer` from `tokenizer` in the project.
rg --type py 'Driver' | grep 'tee'
rg --type py 'get_tokenizer' | grep 'tokenizer'

Length of output: 925

@sudoskys sudoskys linked an issue Apr 13, 2024 that may be closed by this pull request
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.

[BUG] Too many trash code
1 participant