Commit graph

22 commits

Author SHA1 Message Date
hlohaus
77afb46c50 Update RequestConfig to set download_media default to False and add raw parameter; modify AsyncCompletions to handle raw_response correctly 2025-10-09 19:39:13 +02:00
hlohaus
1edd0fff17 Refactor model handling and improve timeout functionality
- Removed empty string mapping from model_map in AnyModelProviderMixin.
- Updated clean_name function to exclude 'chat' from version patterns.
- Added stream_timeout parameter to AsyncGeneratorProvider for more flexible timeout handling.
- Enhanced chunk yielding in AsyncAuthedProvider to support stream_timeout, allowing for better control over asynchronous responses.
2025-09-04 18:11:05 +02:00
hlohaus
9868a88199 Fix audio response in API 2025-07-16 10:27:12 +02:00
hlohaus
2befef988b feat: refactor provider create functions to class attributes and update calls
- Added `create_function` and `async_create_function` class attributes with default implementations in `base_provider.py` for `AbstractProvider`, `AsyncProvider`, and `AsyncGeneratorProvider`
- Updated `get_create_function` and `get_async_create_function` methods to return these class attributes
- Replaced calls to `provider.get_create_function()` and `provider.get_async_create_function()` with direct attribute access `provider.create_function` and `provider.async_create_function` across `g4f/__init__.py`, `g4f/client/__init__.py`, `g4f/providers/retry_provider.py`, and `g4f/tools/run_tools.py`
- Removed redundant `get_create_function` and `get_async_create_function` methods from `providers/base_provider.py` and `providers/types.py`
- Ensured all provider response calls now use the class attributes for creating completions asynchronously and synchronously as needed
2025-06-12 12:45:55 +02:00
hlohaus
5734a06193 feat: Enhance PollinationsAI with new models and media handling
- Updated `PollinationsAI.py` to import `quote` and `ClientTimeout` from `aiohttp`.
- Added `MissingAuthError` to error imports in `PollinationsAI.py`.
- Included `AudioResponse` in response imports in `PollinationsAI.py`.
- Expanded `image_models` in `PollinationsAI` to include "turbo" and "gptimage".
- Changed the initialization of `image_models` to use `cls.image_models.copy()`.
- Introduced `download_media` parameter in the `_generate_image` method.
- Added a condition to set `n = 1` if the model is "gptimage".
- Renamed `get_image_url` to `get_url_with_seed` and modified its logic to return the URL for "gptimage".
- Updated the session creation in `_generate_image` to include a timeout.
- Enhanced error handling in the image fetching logic to yield `Reasoning` status.
- Modified the media handling in `save_response_media` to yield `AudioResponse` based on `download_media`.
- Updated `OpenAIFM.py` to include `quote` and `AudioResponse` imports.
- Added `styles` to the `OpenAIFM` class and created a method to group models.
- Introduced `download_media` parameter in the `synthesize` method of `OpenAIFM`.
- Updated the `create_app` function in `api/__init__.py` to check for `a2wsgi` availability.
- Removed unused file handling routes in `api/__init__.py`.
- Updated `secure_filename` function in `files.py` to handle encoding more robustly.
- Added `download_media` to the `RequestConfig` model in `stubs.py`.
2025-06-12 08:37:42 +02:00
hlohaus
93986d15f6 fix: resolve model duplication and improve provider handling
- Fixed duplicate model entries in Blackbox provider model_aliases
- Added meta-llama- to llama- name cleaning in Cloudflare provider
- Enhanced PollinationsAI provider with improved vision model detection
- Added reasoning support to PollinationsAI provider
- Fixed HuggingChat authentication to include headers and impersonate
- Removed unused max_inputs_length parameter from HuggingFaceAPI
- Renamed extra_data to extra_body for consistency across providers
- Added Puter provider with grouped model support
- Enhanced AnyProvider with grouped model display and better model organization
- Fixed model cleaning in AnyProvider to handle more model name variations
- Added api_key handling for HuggingFace providers in AnyProvider
- Added see_stream helper function to parse event streams
- Updated GUI server to handle JsonConversation properly
- Fixed aspect ratio handling in image generation functions
- Added ResponsesConfig and ClientResponse for new API endpoint
- Updated requirements to include markitdown
2025-05-16 00:18:12 +02:00
hlohaus
e5a49cdb6d Set return_conversation to True 2025-04-26 23:10:06 +02:00
hlohaus
c3632984f7 feat: add audio speech generation endpoint and media handling refactor
- Added new `/v1/audio/speech` and `/api/{path_provider}/audio/speech` endpoints in `g4f/api/__init__.py` for generating speech from text
- Introduced `AudioSpeechConfig` model in `g4f/api/stubs.py` with fields for input, model, provider, voice, instructions, and response format
- Updated `PollinationsAI.py` to support `modalities` in `kwargs` when checking for audio
- Set default voice for audio models in `PollinationsAI.py` if not provided in `kwargs`
- Added debug print in `PollinationsAI.py` to log request data to text API endpoint
- Extended supported FastAPI response types in `g4f/api/__init__.py` to include `FileResponse` from `starlette.responses`
- Added `BackgroundTask` to clean up generated audio files after serving in `g4f/api/__init__.py`
- Modified `AnyProvider.py` to include `EdgeTTS`, `gTTS`, and `MarkItDown` as audio providers when `audio` is in `kwargs` or `modalities`
- Created `resolve_media` helper in `g4f/client/__init__.py` to standardize media handling for audio/image input
- Replaced manual media preprocessing in `Completions`, `AsyncCompletions`, and `Images` classes with `resolve_media`
- Added `/docs/README.md` with a link to the documentation site
2025-04-26 12:21:49 +02:00
hlohaus
b15a83ae13 feat: add audio transcription endpoint and MarkItDown audio provider integration
- Added new MarkItDown audio provider in g4f/Provider/audio/MarkItDown.py for handling audio transcription using markitdown external module
- Included MarkItDown provider import in g4f/Provider/audio/__init__.py
- Implemented /v1/audio/transcriptions POST API endpoint with support for file upload, model selection, provider choice, and prompt in g4f/api/__init__.py
- Added TranscriptionResponseModel Pydantic schema to g4f/api/stubs.py for transcription responses
- Fixed media tuple handling in g4f/client/__init__.py to correctly unpack and assign file/name pairs in Completions, Images, and AsyncCompletions classes
- Updated g4f/Provider/LambdaChat.py to remove redundant origin attribute and simplify URL assignment
- Added handling in AnyProvider to append provider if model is matched in provider map and provider is working (g4f/providers/any_provider.py)
- Modified backend_api.py to fix web_search logic and default filter_markdown parameter extraction from query parameters
2025-04-26 02:21:30 +02:00
hlohaus
1296b3f64f refactor: update audio parameter handling in EdgeTTS and stubs
- Remove the unused `language`, `locale`, and `extra_parameters` parameters from the `EdgeTTS` function signature in `g4f/Provider/audio/EdgeTTS.py`.
- Update voice selection logic to check for `"locale"` and `"language"` keys in the `audio` dictionary, defaulting to `cls.default_locale` when neither is provided, and modify the error message accordingly.
- Refactor extraction of extra parameters by building a dict from the `audio` dictionary for keys `"rate"`, `"volume"`, and `"pitch"`.
- In `g4f/api/stubs.py`, remove the try/except block for importing `Annotated` and import `Messages` from `..typing` instead.
- Add an optional `audio: Optional[dict] = None` field to the `ImageGenerationConfig` model.
2025-04-19 03:51:37 +02:00
BuT9l3b
2fd5d773a2 fix(ImageGenerationConfig): add size="WxH" support
- Parse `size` string (e.g., "256x256") to auto-set `width` and `height`
- Keep explicit `width`/`height` priority if both provided

Fixes xtekky#2902
2025-04-15 09:21:39 +03:00
hlohaus
8c2c46b20f Support "Think Deeper" in Copilot
Improve Documentation
2025-03-30 15:40:46 +02:00
hlohaus
5ae71adbae Small changes 2025-03-24 11:35:41 +01:00
hlohaus
8f6efd5366 Update docs: Using the OpenAI Library
Add sse function to requests sessions
Small improvments in OpenaiChat and ARTA provider
2025-03-22 07:32:30 +01:00
hlohaus
705ad02954 Add audio example usage 2025-03-21 05:13:59 +01:00
hlohaus
c97ba0c88e Add audio transcribing example and support
Add Grok Chat provider
Rename images parameter to media
Update demo homepage
2025-03-21 03:17:45 +01:00
hlohaus
713ad2c83c Add many parameters to API endpoints
Support conversational HuggingFace providers
Fix streaming in PollinationsAI provider
2025-03-11 22:16:03 +01:00
hlohaus
fd97cceab0 Restore AsyncClient streaming return type
Improve error handling in DDG
use OpenaiAPI provider in DeepInfraChat
Support api_base and response_type parameters in API
2025-01-24 04:56:26 +01:00
Heiner Lohaus
7893a0835e Add filessupport, scrape and refine your data
Remove Webdriver usages
Add continue messages for other providers
2025-01-01 04:20:02 +01:00
Heiner Lohaus
75fe95cbed Add continue messages support,
Remove old text_to_speech service from gui
Update gui and client readmes,
Add HuggingSpaces group provider;
Add providers parameters config forms to gui
2024-12-30 02:51:36 +01:00
H Lohaus
86e36efe6b
Add Path and PathLike support when uploading images (#2514)
* Add Path and PathLike support when uploading images
Improve raise_for_status in special cases
Move ImageResponse to providers.response module
Improve OpenaiChat and OpenaiAccount providers
Add Sources for web_search in OpenaiChat
Add JsonConversation for import and export conversations to js
Add RequestLogin response type
Add TitleGeneration support in OpenaiChat and gui
* Improve Docker Container Guide in README.md
* Add tool calls api support, add search tool support
2024-12-28 16:50:08 +01:00
H Lohaus
bbb858249b
Improve gradient in gui, show only models with enabled providers (#2492)
- **Cloudflare Provider**: Added error handling for missing requirements when fetching arguments.
- **Copilot Provider**: Updated the prompt formatting to use a maximum length function, improving message handling.
- **PollinationsAI Provider**: Adjusted the prompt length to a maximum of 5000 characters.
- **GitHub Copilot Provider**: Updated to use `ClientSession` for better session management.
- **CSS Updates**: Enhanced the gradient styling in the GUI for a more visually appealing interface.
- **JavaScript Updates**: Added functionality to toggle search options in the chat interface.
2024-12-17 21:17:40 +01:00