-
-
Notifications
You must be signed in to change notification settings - Fork 13.7k
feat: Improve handling of media and API response structures #2964
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
Conversation
- Added validation for `media` parameter in `MarkItDown` class to raise `ValueError` if `media` is not provided.
- Included a check for `has_markitdown` in `MarkItDown` class to raise `ImportError` if `markitdown` is not installed.
- Refactored API response structure by defining `responses` as a reusable dictionary in `g4f/api/__init__.py`.
- Updated `/v1/chat/completions` endpoint to include a new parameter `conversation_id` in the `chat_completions` function.
- Enhanced logic in `chat_completions` to set `conversation_id` from configuration or function input.
- Added a new endpoint `/api/{provider}/{conversation_id}/chat/completions` in `g4f/api/__init__.py` to handle chat completions with `conversation_id`.
- Replaced duplicate response dictionary definitions with the reusable `responses` dictionary in the `/api/{provider}/chat/completions` and `/v1/chat/completions` endpoints.
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 for "feat: Improve handling of media and API response structures"
Hi H Lohaus,
Thank you for your contribution to the project! This PR brings several valuable improvements around media validation and API response management.
Highlights
- Strict validation for the
mediaparameter inMarkItDownstreamlines error handling upfront. - Clear and proactive import check for
markitdownprevents obscure runtime issues. - DRY refactor of response dictionaries into a reusable
responsesvariable simplifies maintenance and reduces duplication. - Adding
conversation_idsupport in/v1/chat/completionsand new dedicated endpoint/api/{provider}/{conversation_id}/chat/completionsgreatly enhances conversational context handling. - Consistent use of
responsesdict across endpoints ensures uniform API documentation and behavior.
Suggestions
- The two
provider_chat_completionsendpoint functions share the same name but have different signatures. Renaming one (e.g.,provider_chat_conversation_completions) would improve clarity and avoid possible confusion. - It may be helpful to add tests validating the new error cases raised in
MarkItDown(ValueErrorandImportError) to ensure these guardrails remain effective. - In the async generator inside
MarkItDown.py, could you confirm theMaItDo()class/function is correctly named? It stands out since the class isMarkItDown, but the instance isMaItDo()—just want to ensure that is intentional.
Overall, this is a solid step toward cleaner API design and improved media handling. Looking forward to the updates!
Thanks again for enhancing the codebase.
Best regards,
g4f copilot
- Changed default value of `return_conversation` from `False` to `True` in `Grok._create_completion` method in `g4f/Provider/needs_auth/Grok.py`
- Updated HTTP 200 response mapping to use `{"content": {"audio/*": {}}}` instead of `{"class": FileResponse}` in `Api.markdown_to_audio` method in `g4f/api/__init__.py
Review of Pull Request by H LohausSummaryThanks for the contribution! This pull request adds several useful features, including improved error handling, API structure refactoring, and new endpoints for handling Key Changes
Minor Suggestions:
OverallGreat work on improving both the functionality and structure of the codebase. The refactoring and added validations will certainly make the project more robust and easier to maintain. Thanks again for contributing! Approve ✅ |
Pull Request ReviewSummaryThank you for your contributions, H Lohaus! This pull request introduces several important improvements to the handling of media and API response structures, including better validation, error handling, and API enhancements. Changes Overview
Code ReviewPositive Points
Suggestions
Minor Observations
ConclusionOverall, this pull request brings valuable enhancements and improvements to both the API and media handling in the project. Thank you for your work on this, H Lohaus! Looking forward to seeing these changes merged! |
…e.py - Replaced inline `get_args_from_nodriver` logic with a new async function `nodriver_read_models` inside `Cloudflare` class - Added `async def nodriver_read_models()` to handle asynchronous execution of `get_args_from_nodriver` and call `read_models()` - Moved `try/except` block for handling `RuntimeError` and `FileNotFoundError` inside the new async function - Updated fallback assignment `cls.models = cls.fallback_models` and debug logging to be within `nodriver_read_models` exception handler - Replaced `asyncio.run(args)` with `asyncio.run(nodriver_read_models())` to execute the new async function - Modified logic inside `except ResponseStatusError` block in `Cloudflare` class to incorporate the new structure
Pull Request Review: feat: Improve handling of media and API response structuresReview SummaryThank you, H Lohaus, for contributing to the project and enhancing its functionality. Your pull request provides thoughtful improvements across several areas, including media validation, API response structure refactoring, and the introduction of a new endpoint for handling Strengths
Suggestions for Improvement
Overall, this pull request significantly improves the project's functionality, usability, and maintainability. Thank you for your valuable contributions. Once the above considerations are addressed, I recommend merging this pull request. Great work, H Lohaus! Action Items
|
mediaparameter inMarkItDownclass to raiseValueErrorifmediais not provided.has_markitdowninMarkItDownclass to raiseImportErrorifmarkitdownis not installed.responsesas a reusable dictionary ing4f/api/__init__.py./v1/chat/completionsendpoint to include a new parameterconversation_idin thechat_completionsfunction.chat_completionsto setconversation_idfrom configuration or function input./api/{provider}/{conversation_id}/chat/completionsing4f/api/__init__.pyto handle chat completions withconversation_id.responsesdictionary in the/api/{provider}/chat/completionsand/v1/chat/completionsendpoints.