Commit graph

86 commits

Author SHA1 Message Date
Ammar
7771cf3d43
Improve Yupp provider account handling , request timeout and get byte from url (#3249)
* 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.
2025-11-26 14:02:51 +01:00
hlohaus
2317bd5a83 Refactor MarkItDown and OpenaiChat classes for improved media handling and optional parameters; enhance is_data_an_media function to support binary/octet-stream return type for unsupported URLs. 2025-10-31 18:16:19 +01:00
hlohaus
9b3e7a69d2 Refactor Dockerfile and backend API for improved image processing and dependency management 2025-10-31 03:52:10 +01:00
hlohaus
da6c00e2a2 Refactor Cloudflare and LMArena providers to enhance authentication handling and improve WebSocket communication 2025-10-30 21:34:45 +01:00
hlohaus
6b210f44f9 Refactor search and response handling; introduce CachedSearch and DDGS classes for improved web search functionality and response management. Add PlainTextResponse for handling plain text responses. Update requirements and setup for new dependencies. 2025-10-03 11:38:24 +02:00
H Lohaus
6935580bd7
Update g4f/image/__init__.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-03 17:11:43 +02:00
Ammar
fe24210db2 add upload_file
- add upload_file
- add conversation_mode
- add temporary
2025-08-29 16:27:41 +03:00
hlohaus
fe79b11070 Fix Azure image 2025-08-06 08:16:27 +02:00
hlohaus
00bd517f27 feat: add image generation support to Azure provider
- 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
2025-08-06 07:18:48 +02:00
hlohaus
9868a88199 Fix audio response in API 2025-07-16 10:27:12 +02:00
hlohaus
b49d71db7c Auth on Cloudflare error 2025-07-15 23:43:55 +02:00
hlohaus
c4b18df769 Support audio model in Azure provider 2025-07-12 19:41:23 +02:00
hlohaus
3c66fa114a feat: add 'transparent' image model and refactor HAR provider auth flow
- 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
2025-07-11 01:46:32 +02:00
hlohaus
031f09b2e6 Fix generate thumbnails 2025-07-10 06:25:07 +02:00
hlohaus
bdc356c4c2 refactor: replace constants module with config module
- 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.
2025-07-09 23:21:03 +02:00
hlohaus
664b1ce650 Add any_model_map 2025-06-28 06:22:31 +02:00
hlohaus
c9755196f8 Fix sending images, fix unittests 2025-06-27 16:44:43 +02:00
hlohaus
315495e199 Support inlineData in GeminiPro 2025-06-26 00:25:53 +02:00
hlohaus
5b4f98c069 Move file functions 2025-06-24 22:32:59 +02:00
hlohaus
744dfeb957 Add ip ban 2025-06-24 22:25:42 +02:00
hlohaus
ffb1914cbe Improve update script 2025-06-19 21:02:52 +02:00
hlohaus
295103f224 Improve update script 2025-06-19 15:24:49 +02:00
hlohaus
9f941ae71b Support timeout in backend_api 2025-06-19 12:18:53 +02:00
hlohaus
90262b1f6a Fix copy image 2025-06-19 10:40:36 +02:00
hlohaus
04b59558b4 Update video provider 2025-06-19 10:04:43 +02:00
hlohaus
4337fa7fa8 Add user log 2025-06-19 06:19:54 +02:00
hlohaus
6120c791a9 fix: Update header fallback for last-modified date in copy_images.py
- 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
2025-06-19 02:23:35 +02:00
hlohaus
2812c30987 quote_url 2025-06-19 01:17:27 +02:00
hlohaus
a354a2e8f8 Update copy_image 2025-06-18 00:06:49 +02:00
hlohaus
b7d1a03dfc Add video provider 2025-06-17 16:30:00 +02:00
hlohaus
4bd1b8652c Fix copy images 2025-06-17 08:30:08 +02:00
hlohaus
992023766a Update process_image 2025-06-15 18:30:32 +02:00
hlohaus
b400052a25 Use ImageOps 2025-06-15 17:42:00 +02:00
hlohaus
be8366bb8a Update render_messages 2025-06-15 17:32:27 +02:00
hlohaus
424d44e6ed Fix broken thumbnails 2025-06-15 15:55:54 +02:00
hlohaus
6dbe827a8f Add quality=75, exif=None to save thumbnail 2025-06-15 15:16:45 +02:00
hlohaus
0b86b09a50 Fix image orintation 2025-06-15 14:23:57 +02:00
hlohaus
3024cc5c9e Support uploaded images 2025-06-15 14:17:28 +02:00
hlohaus
6ae75f56dc Use ROTATE_90 2025-06-15 13:46:20 +02:00
hlohaus
cc5d0e9c85 Update process generate thumbnails 2025-06-15 12:53:12 +02:00
hlohaus
c6bfddecae Update process generate thumbnails 2025-06-15 12:48:24 +02:00
hlohaus
20a47d85d9 Fix image orientation 2025-06-15 04:03:47 +02:00
hlohaus
70a0c9aec7 Add support thumbnail for generated images 2025-06-15 03:21:30 +02:00
hlohaus
b706256eda Remove rotate image 2025-06-15 02:47:41 +02:00
hlohaus
3066a6031d Fix image links 2025-06-15 02:26:00 +02:00
hlohaus
27507318e6 Update check valid images 2025-06-15 01:25:42 +02:00
hlohaus
aea736d41e Add thumbnail support 2025-06-15 00:42:48 +02:00
hlohaus
74b3137107 Fix load share conversation 2025-06-15 00:06:16 +02:00
hlohaus
963c3a585e refactor: Refactor image generation parameters handling
- 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.
2025-06-12 14:23:04 +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