-
Notifications
You must be signed in to change notification settings - Fork 227
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
Conversation
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
WalkthroughThe 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 Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
from typing import Union, List, Optional, Literal |
# 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) |
There was a problem hiding this comment.
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.
llmkira/sdk/endpoint/__init__.py
Outdated
@@ -4,11 +4,10 @@ | |||
# @File : __init__.py | |||
# @Software: PyCharm | |||
|
|||
|
There was a problem hiding this comment.
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:
- The
Driver
class is still being used inllmkira/sdk/endpoint/schema.py
,llmkira/sdk/endpoint/openai/__init__.py
, and an external script indocs/test_script/note_openai_req.py
. - The function
get_tokenizer
is still being used inllmkira/schema.py
and is defined inllmkira/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
Summary by CodeRabbit
New Features
Cost
class for detailed cost management.driver
inUserConfig
class for enhanced configuration.pyproject.toml
.Bug Fixes
Driver
class to ensure endpoint accuracy.Refactor
UserCost
andLlmConfig
classes to streamline configuration settings.Documentation
CostControl
class to reflect current functionalities.