-
Notifications
You must be signed in to change notification settings - Fork 7
Improve openai class #601
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
Merged
Merged
Improve openai class #601
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zeiler
approved these changes
May 27, 2025
zeiler
reviewed
May 27, 2025
zeiler
approved these changes
May 27, 2025
Minimum allowed line rate is |
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant enhancements to the OpenAI-compatible API server implementation, including code refactoring, new utility methods, and improved error handling. The changes streamline request processing, add modularity, and simplify parameter extraction and validation. Minor updates include type cleanup and debugging code removal.
Enhancements to OpenAI-compatible API server:
Refactored request parameter handling:
_extract_request_params
to centralize and validate parameter extraction from request data. This reduces redundancy across methods._create_completion_args
to construct completion arguments dynamically, improving flexibility for both streaming and non-streaming requests.Improved error handling:
_format_error_response
to generate OpenAI-compatible error responses in a structured JSON format.Simplified request processing:
_process_request
and_process_streaming_request
to use**kwargs
and leverage the new helper methods for argument preparation. This reduces boilerplate code and enhances maintainability.Class initialization updates:
load_model
with__init__
to initialize the OpenAI client and model more effectively. Addedget_model
as an abstract method for subclasses to specify the model name.Code cleanup and minor updates:
Type cleanup:
Optional
,List
) inclarifai/runners/models/openai_class.py
.Debugging code removal:
async def main()
inclarifai/runners/utils/code_script.py
.String handling adjustment:
_parse_default_value
to return raw strings forSTR
data types instead of usingrepr
, ensuring consistent handling of string defaults.