* Add image caching to Yupp provider
Introduces an image cache to avoid redundant uploads in the Yupp provider. Refactors media attachment handling into a new prepare_files method, improving efficiency and code organization. Updates .gitignore to exclude .idea directory.
* Refactor Yupp stream handling and chunk processing
Improves stream segmentation in the Yupp provider by introducing buffers for target, variant, quick, thinking, and extra streams. Refactors chunk processing to better handle image-gen, quick responses, and variant outputs, and adds more robust stream ID extraction and routing logic. Yields a consolidated JsonResponse with all stream segments for downstream use.
* Handle ClientResponseError in Yupp provider
Adds specific handling for aiohttp ClientResponseError in the Yupp provider. Marks account as invalid on 500 Internal Server Error, otherwise increments error count and raises ProviderException for other errors.
* Update Yupp.py
fix 429 'Too Many Requests'
* Update Yupp.py
* Improve Yupp provider account handling and request timeout
Refactored account loading to preserve account history and error counts when updating tokens. Enhanced request logic to support custom timeouts using aiohttp's ClientTimeout, allowing for more flexible timeout configuration.
* Update __init__.py
* Handle multi-line <think> and <yapp> blocks in Yupp
Added logic to capture and process multi-line <think> and <yapp class="image-gen"> blocks referenced by special IDs. Introduced block storage and extraction functions, enabling reasoning and image-gen content to be handled via references in the response stream.
* Update LMArena.py
Not Found Model error
* Refactor to use StreamSession in Qwen and Yupp providers
Replaced aiohttp.ClientSession with StreamSession in Qwen.py and Yupp.py for improved session handling. Updated exception and timeout references in Yupp.py to use aiohttp types. Improved default argument handling in StreamSession initialization.
* Update Yupp.py
* Add status parameter to get_generated_image method
Introduces a 'status' parameter to the get_generated_image method to allow passing image generation status. Updates method calls and response objects to include status in their metadata for improved tracking of image generation progress.
* Update OpenaiChat.py
* Refactor Qwen image upload and caching logic and token
Reworked the image upload flow in Qwen provider to use direct file uploads with OSS headers, added caching for uploaded images, and improved file type detection. Updated prepare_files to handle uploads via session and cache results, and added utility for generating OSS headers. Minor imports and typing adjustments included and token support.
* Refactor Qwen and Yupp providers for improved async handling
Updated Qwen provider to handle timeout via kwargs and improved type annotations. Refactored Yupp provider for better code organization, formatting, and async account rotation logic. Enhanced readability and maintainability by reordering imports, adding whitespace, and clarifying function implementations.
* Add image caching to OpenaiChat provider
Introduces an image cache mechanism to OpenaiChat for uploaded images, reducing redundant uploads and improving efficiency. Also refactors code for clarity, updates type hints, and makes minor formatting improvements throughout the file.
- Updated `Azure.create_completion` to support media uploads and image generation via `/images/` endpoint
- Added `media` parameter to `Azure.create_completion` and handled image-related request formatting
- Imported `StreamSession`, `FormData`, `raise_for_status`, `get_width_height`, `to_bytes`, `save_response_media`, and `format_media_prompt` in `Azure.py`
- Modified `get_models` to load `AZURE_API_KEYS` from environment and parse it into `cls.api_keys`
- Adjusted `get_width_height` in `image/__init__.py` to return higher default resolutions for "16:9" and "9:16" aspect ratios
- Modified `save_response_media` in `image/copy_images.py` to accept optional `content_type` parameter and use it when provided
- Updated `FormData` class logic in `requests/curl_cffi.py` to define it only when `has_curl_mime` is True and raise an error otherwise
- Added "transparent" to `image_models` in `PollinationsAI` and mapped it to "gptimage"
- Modified transparent flag handling in `_generate_image` call in `PollinationsAI`
- Removed unused `cls.get_models()` call from image generation method in `PollinationsAI`
- Replaced `AsyncGeneratorProvider` with `AsyncAuthedProvider` in `HarProvider`
- Implemented `on_auth_async` in `HarProvider` to support browser-based auth via `nodriver`
- Replaced `create_async_generator` with `create_authed` in `HarProvider` to support `AuthResult`
- Removed custom `headers` in HAR post requests; used `auth_result.get_dict()` for `StreamSession`
- Refactored `Video` provider to support optional search in `get_response`
- Added `search` parameter to `RequestConfig.get_response` and `Video.create_async_generator`
- Improved browser automation and element interaction logic in `Video` provider
- Extracted video request interception to collect URLs using `nodriver`
- Reduced video polling loop timeout from 600 to 300 iterations in `Video`
- Updated CLI `client.py` to fix handling of `conversation.conversation` assignment
- Fixed argparse config: removed `nargs='?'` and added `metavar` for `--conversation-file`
- Improved image metadata extraction in API and backend when Pillow is available
- Modified `ImageResponse.__str__` to output HTML anchor/image tags with dimensions if present
- Added support for returning `target_path` from `copy_media` if `return_target` is True
- Changed default image processing size in `process_image` from 800x400 to 400x400
- Disabled RGBA-to-RGB flattening in `process_image`
- Improved `get_args_from_nodriver` to ensure proper referer and cookie handling
- Added helper `get_target_paths_and_urls` in `Api` to extract image dimensions from disk paths
- Replaced imports of `STATIC_URL` from `..constants` to `..config` in:
- `g4f/Provider/PollinationsAI.py`
- `g4f/Provider/PollinationsImage.py`
- Updated `client.py` to import `CONFIG_DIR` and `COOKIES_DIR` from `g4f.config` instead of defining platform-specific directories.
- Changed the handling of conversation history in `ConversationManager`:
- Updated `self.history` to retrieve data from `data.get("items", [])` instead of `data.get("history", [])`.
- Modified the `stream_response` function to use `media` instead of `image` for handling media content.
- Updated the `save_content` function to accept `media_content` of type `Optional[MediaResponse]` instead of `content`.
- Adjusted the `run_client_args` function to handle media URLs and files more effectively, appending valid media to a list.
- Removed the `constants.py` file and added a new `config.py` file to centralize configuration settings.
- Updated the `CookiesConfig` class to set `cookies_dir` based on the existence of `CUSTOM_COOKIES_DIR`.
- Adjusted the `render` function in `website.py` to correctly handle file paths and requests for HTML files.
- Updated various references to use the new `config` module instead of the removed `constants` module.
- In g4f/image/copy_images.py, modified the line that retrieves the "date" header
- Changed from `date = response.headers.get("date")` to `date = response.headers.get("last-modified", response.headers.get("date"))` to fallback to "date" if "last-modified" is missing
- No other files or functions were modified besides this line
- Updated the `PollinationsAI` class in `g4f/Provider/PollinationsAI.py`:
- Changed `aspect_ratio` parameter handling to conditionally use default "1:1" if not specified.
- Enhanced media handling by introducing `media` parameter in `_generate_image` method.
- Updated parameter processing in `_generate_image_async` method for `model == "gptimage"`.
- Updated `Api` class in `g4f/api/__init__.py`:
- Simplified handling of `credentials` for `config.api_key`.
- Updated `Images` class in `g4f/client/__init__.py`:
- Added `download_media` parameter to `_process_image_response` method.
- Enhanced `_process_image_response` method to conditionally download media based on `download_media` flag.
- Updated `_process_image_response` method in `Images` class in `g4f/client/__init__.py`:
- Enhanced handling of media response based on `download_media` flag.
- Updated `is_valid_media` function in `g4f/image/__init__.py`:
- Added typing annotations for clarity.
- Updated `AnyProvider` class in `g4f/providers/any_provider.py`:
- Improved handling of `api_key` dictionary to set `extra_body["api_key"]`.
- Updated `IterListProvider` class in `g4f/providers/retry_provider.py`:
- Enhanced handling of `model` and `api_key` parameters.
- Updated `BaseProvider` class in `g4f/providers/types.py`:
- Added `create_function` and `async_create_function` methods.
- Updated `BaseRetryProvider` class in `g4f/providers/types.py`:
- Enhanced handling of `model` and `api_key` parameters in provider iteration.
- 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