-
-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
Update provider parameters, check for valid provider #2594
Conversation
Fix reading model list in GeminiPro Fix check content-type in OpenaiAPI
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.
Pull Request Review: Update provider parameters, check for valid provider
Author: H Lohaus
Summary
This pull request includes the following updates:
- Fixes the reading of the model list in
GeminiPro
. - Fixes the content-type check in
OpenaiAPI
.
Review
-
GeminiPro Changes:
- Adding
supports_system_message
attribute is a positive enhancement for better functionality. - The change in
get_models
method now handles theapi_base
parameter correctly and improves error handling by returning fallback models on exceptions.
- Adding
-
OpenaiAPI Changes:
- Improving content-type validation by using
startswith
to allow for more flexibility in content type checking. - The refactoring of the content type checks to simplify and consolidate the logic is beneficial for readability and maintainability.
- Improving content-type validation by using
-
JS and API Improvements:
- The update to the
conversation
parameter check adds more robustness to the code. - The fix in
get_providers
method ensures proper handling of theimage
attribute. - Removal of redundant
web_search
parameter indecorated_log
improves clarity.
- The update to the
-
Base Provider Changes:
- Adding parameters such as
safe
,enhance
, andprivate
improves the functionality and usability of the provider. - Including
stop
andtools
inBASIC_PARAMETERS
ensures that these settings are available by default.
- Adding parameters such as
Suggestions
- Ensure to update corresponding tests to reflect these changes, especially for the
get_models
method inGeminiPro
and thecontent-type
checks inOpenaiAPI
. - Consider adding more detailed logging to capture the reasons for falling back to
fallback_models
inGeminiPro
.
Thank you, H Lohaus, for your valuable contributions to the project. These improvements will significantly enhance the functionality and maintainability of the codebase.
Best regards,
g4f Copilot
@@ -50,7 +52,7 @@ | |||
cls.models.sort() |
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.
Sorting the models in place can have side effects if the list is used elsewhere. It may be better to return a sorted copy using sorted(cls.models)
.
@@ -108,7 +108,8 @@ | |||
if api_endpoint is None: | |||
api_endpoint = f"{api_base.rstrip('/')}/chat/completions" | |||
async with session.post(api_endpoint, json=data) as response: | |||
if response.headers.get("content-type", None if stream else "application/json") == "application/json": | |||
content_type = response.headers.get("content-type", "text/event-stream" if stream else "application/json") | |||
if content_type.startswith("application/json"): | |||
data = await response.json() | |||
cls.raise_error(data) | |||
await raise_for_status(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.
Ensure that raise_for_status
is called after handling the JSON response and errors to avoid potential misinterpretation of response status.
@@ -62,7 +62,7 @@ | |||
"name": provider.__name__, | |||
"label": provider.label if hasattr(provider, "label") else provider.__name__, | |||
"parent": getattr(provider, "parent", None), | |||
"image": getattr(provider, "image_models", None) is not None, | |||
"image": bool(getattr(provider, "image_models", False)), | |||
"vision": getattr(provider, "default_vision_model", None) is not None, |
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.
Similar to the previous line, you might want to use getattr(provider, "default_vision_model", None)
directly instead of checking if it is not None. This can simplify the expression.
@hlohaus Hi. A bit off topic, but I'll write it for your convenience. In order not to forget to update the link to the release version every time, you can use this one: https://github.com/xtekky/gpt4free/releases/latest |
Pull Request Review by g4f CopilotThank you, @hlohaus, for your contribution to the project! This pull request contains several improvements across multiple files, tackling both functionality correctness and maintainability. Here's my detailed review: Highlights from the PR
Suggestions for Improvement
Overall FeedbackThis pull request makes great strides in improving the robustness of provider operations, code clarity, and configurability across several modules. The attention to detail in both API interaction and parameter handling demonstrates a strong focus on stability and usability. Once the suggestions above are addressed, this should be good to merge! Thanks again for your hard work on this substantial and impactful update! Best regards, |
@TheFirstNoob |
Fix reading model list in GeminiPro
Fix check content-type in OpenaiAPI