Commit Graph

29 Commits

Author SHA1 Message Date
hlohaus
d824d77d65 feat: Refactor PollinationsAI and ARTA provider structure
- Updated `PollinationsAI.py` to strip trailing periods and newlines from the prompt before encoding.
- Modified the encoding of the prompt to remove trailing percent signs after URL encoding.
- Simplified the audio response handling in `PollinationsAI.py` by removing unnecessary checks and yielding chunks directly.
- Renamed `ARTA.py` to `deprecated/ARTA.py` and updated import paths accordingly in `__init__.py`.
- Changed the `working` status of the `ARTA` class to `False` to indicate it is deprecated.
- Enhanced the `Video` class in `Video.py` to include aspect ratio handling and improved URL response caching.
- Updated the `RequestConfig` class to use a dictionary for storing URLs associated with prompts.
- Removed references to the `ARTA` provider in various files, including `models.py` and `any_provider.py`.
- Adjusted the `best_provider` assignments in `models.py` to exclude `ARTA` and include `HuggingFaceMedia` where applicable.
- Updated the response handling in `Video.py` to yield cached responses when available.
2025-06-19 00:42:41 +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
c6b85efba2 feat: Add customizable file extension in get_filename_from_url
- Modified `get_filename_from_url` function to accept a second parameter `extension`, with a default value of ".md".
- Updated the return statement in `get_filename_from_url` to use the new `extension` parameter instead of the hardcoded ".md" suffix.
- Adjusted `get_filename` asynchronous function to pass the `extension` retrieved from `await get_file_extension(response)` into `get_filename_from_url`.
2025-05-21 02:16:41 +02:00
hlohaus
9461949542 feat: improve media handling, file conversion, and error management
- Added UUID-based "x-xai-request-id" header and 403 error handling in Grok.py
- Updated backend_api.py to handle empty media results and unsupported file types with error raising and file cleanup
- Simplified render logic in website.py by removing is_live flag and related code
- Changed "audio/wav" MIME type to "audio/x-wav" in image/__init__.py
- Added is_valid_media and is_valid_audio functions to image/__init__.py for stricter media validation
- Enhanced MarkItDown integration in markitdown/__init__.py with convert_stream method supporting non-seekable streams
- Modified _transcribe_audio.py to use recognize_faster_whisper if available, fallback to recognize_google
- Updated providers/helper.py to prioritize "text" key in to_string function
- Improved stream_read_files in files.py to skip DOWNLOADS_FILE and adjust code block formatting
- Added get_filename_from_url utility in files.py for consistent filename generation from URLs
- Enhanced download_urls in files.py to use MarkItDown for URL conversion and improved error logging
- Improved render_part and related functions in media.py to use new media validation logic and handle more cases
- Adjusted merge_media and render_messages in media.py for stricter part filtering and validation
2025-05-20 22:40:12 +02:00
H Lohaus
9936c56644 Update files.py 2025-05-19 17:45:32 +02:00
hlohaus
c0d31c2abb refactor: improve media rendering and response formatting with precise changes
- Modified g4f/providers/response.py to ensure format_images_markdown returns the result directly without additional flags in the 'format_images_markdown' function.
- Updated g4f/gui/server/api.py to add 'tempfiles' parameter with default empty list to '_create_response_stream' method.
- Changed or added code in API response handling to iterate over 'tempfiles' and attempt to remove each file after response completion, with exception handling (try-except block with logger.exception).
- Adjusted g4f/Tools/files.py to fix tempfile creation: corrected the 'suffix' parameter in 'get_tempfile' to use 'suffix' directly instead of splitting.
- In g4f/tools/media.py, changed 'render_part' function to handle 'text' key properly, checking 'part.get("text")' and returning a dictionary with 'type': 'text' and 'text': value, if present.
2025-05-19 08:15:21 +02:00
hlohaus
c0e323b543 Fix build docker image 2025-05-17 17:35:35 +02:00
hlohaus
3775c1e06d fix: improve error handling and add type checks in various providers and API
- Updated error handling in g4f/Provider/DDG.py to raise ResponseError instead of yield error strings
- Replaced yield statements with raises in g4f/Provider/DDG.py for HTTP and response errors
- Added response raising in g4f/Provider/DeepInfraChat.py for image upload responses
- Included model alias validation and error raising in g4f/Provider/hf/HuggingFaceMedia.py
- Corrected model alias dictionary key in g4f/Provider/hf_space/StabilityAI_SD35Large.py
- Ensured referrer parameter default value in g4f/Provider/PollinationsImage.py
- Removed duplicate imports and adjusted get_models method in g4f/Provider/har/__init__.py
- Modified g4f/gui/server/api.py to remove unused conversation parameter in _create_response_stream
- Fixed logic to handle single exception in g4f/providers/retry_provider.py
- Added missing import of JsonConversation in g4f/providers/retry_provider.py
- Corrected stream_read_files to replace extension in return string in g4f/tools/files.py
2025-05-17 10:02:13 +02:00
hlohaus
ab5a089b7e feat: add Qwen Qwen-3 provider and update audio/media handling
- Introduce `Qwen_Qwen_3` provider in `g4f/Provider/hf_space/Qwen_Qwen_3.py`
- Register Qwen_Qwen_3 in `g4f/Provider/hf_space/__init__.py` and add it to `HuggingSpace`
- Update `MarkItDown` in `g4f/Provider/audio/MarkItDown.py` to accept and forward `llm_client` and `llm_model` kwargs; add async handling for `text_content`
- Modify audio route in `g4f/api/__init__.py` to pass `llm_client` for MarkItDown and set `modalities` only for other providers
- Adjust `OpenaiChat` (needs_auth) to merge media for upload and check for media presence before requesting images
- Change `get_tempfile` in `g4f/tools/files.py` to determine suffix from file extension using `os.path.splitext`
- Refactor provider listing and model mapping in `AnyProvider.get_models()` (g4f/providers/any_provider.py) to update provider order, support new `HarProvider`, initialize attributes, and guard against model_aliases being None
- Ensure `AnyProvider.create_async_generator` calls `get_models` before working with providers
2025-05-01 10:22:12 +02:00
hlohaus
e238ca3a58 refactor: update model mappings, error handling, and file utils
- Changed `generate_commit_message` return to `.strip("`").strip()` in `commit.py`
- Added new model mappings in `PollinationsAI.py`, including `gpt-4.1`, `gpt-4.1-mini`, and `deepseek-r1-distill-*`
- Removed `print` debug statement from `PollinationsAI.py` request payload
- Replaced temp file handling in `MarkItDown.py` with `get_tempfile` utility
- Added `get_tempfile` function to `files.py` for consistent tempfile creation
- Added `gpt-4.1` to `text_models` list in `models.py`
- Added `ModelNotSupportedError` to exception handling in `OpenaiChat.py`
- Updated message content creation to use `to_string()` in `OpenaiChat.py`
- Wrapped `get_model()` in try-except to ignore `ModelNotSupportedError` in `OpenaiChat.py`
- Adjusted `convert` endpoint in `api/__init__.py` to accept optional `provider` param
- Refactored `/api/markitdown` to reuse `convert()` handler in `api/__init__.py
2025-04-26 17:50:48 +02:00
hlohaus
8f63f656a2 feat: enhance HAR provider, image handling, markdown upload & cache
- **g4f/Provider/har/__init__.py**
  - `get_models`/`create_async`: iterate over `(domain, harFile)` and filter with `domain in request_url`
  - `read_har_files` now yields `(domain, har_data)`; fixes file variable shadowing and uses `json.load`
  - remove stray `print`, add type hint for `find_str`, replace manual loops with `yield from`
  - small whitespace clean-up

- **g4f/Provider/needs_auth/Grok.py**
  - `ImagePreview` now passes `auth_result.cookies` and `auth_result.headers`

- **g4f/Provider/needs_auth/OpenaiChat.py**
  - add `Union` import; rename/refactor `get_generated_images` → `get_generated_image`
  - support `file-service://` and `sediment://` pointers; choose correct download URL
  - return `ImagePreview` or `ImageResponse` accordingly and stream each image part
  - propagate 422 errors, update prompt assignment and image handling paths

- **g4f/client/__init__.py**
  - drop unused `ignore_working` parameter in sync/async `Completions`
  - normalise `media` argument: accept single tuple, infer filename when missing, fix index loop
  - `Images.create_variation` updated to use the new media logic

- **g4f/gui/server/api.py**
  - expose `latest_version_cached` via `?cache=` query parameter

- **g4f/gui/server/backend_api.py**
  - optional Markdown extraction via `MarkItDown`; save rendered text as `<file>.md`
  - upload flow rewrites: copy to temp file, move to bucket/media dir, clean temp, store filenames
  - introduce `has_markitdown` guard and improved logging/exception handling

- **g4f/tools/files.py**
  - remove trailing spaces in HAR code-block header string

- **g4f/version.py**
  - add `latest_version_cached` `@cached_property` for memoised version lookup
2025-04-24 15:18:21 +02:00
hlohaus
c083f85206 feat: improve file handling and streamline provider implementations
- Added file upload usage example with bucket_id in docs/file.md
- Fixed ARTA provider by refactoring error handling with a new raise_error function
- Simplified aspect_ratio handling in ARTA with proper default
- Improved AllenAI provider by cleaning up image handling logic
- Fixed Blackbox provider's media handling to properly process images
- Updated file tools to handle URL downloads correctly
- Fixed bucket_id pattern matching in ToolHandler.process_bucket_tool
- Cleaned up imports in typing.py by removing unnecessary sys import
- Fixed inconsistent function parameters in g4f/tools/files.py
- Fixed return value of upload_and_process function to return bucket_id
2025-04-08 19:00:44 +02:00
hlohaus
6c8387f045 Update handle media uploads 2025-03-30 00:04:13 +01:00
hlohaus
fa17ce1bd6 Delete buckets with the conversation
Fix lightbox for uploaded images
Fix save media content
Fix TypeGPT and Cloudflare provider
2025-03-29 11:22:22 +01:00
hlohaus
46d0b87008 Add example for video generation
Add support for images in messages
2025-03-27 09:38:31 +01:00
hlohaus
3c546897ec Fix missing bucket cache file 2025-03-25 12:39:03 +01:00
hlohaus
e76e5f7835 Use dynamtic aspect_ratio for image and video size 2025-03-23 14:47:26 +01:00
hlohaus
6314d27dc4 Fix url download function 2025-02-22 14:20:54 +01:00
hlohaus
ba60296677 Fix unittest, update model lists 2025-02-22 13:19:52 +01:00
hlohaus
796d6d6e14 Fix errors on read buckets
Update requirements for docx
2025-02-19 17:10:03 +01:00
hlohaus
5676752ca4 Fix copy_images, Add support .arc files 2025-02-12 16:30:24 +01:00
hlohaus
9994bb67a1 Add zerogpu_uuid to demo 2025-02-05 17:07:20 +01:00
hlohaus
efacc15d92 Support options like max_depth in downloads.json
Add created buckets automatic to messages
Don't add images to scrape result without title
2025-01-28 22:33:49 +01:00
hlohaus
ab04d1d894 Increase max token in HuggingfaceAPI
Restore browser instance on start up errors in nodriver
Restored instances can be used as usual or to stop the browser
Add demo modus to web ui for HuggingSpace
Add rate limit support to web ui. Simply install flask_limiter
Add home for demo with Access Token input and validation
Add stripped model list for demo
Add ignores for encoding error in web_search and file upload
2025-01-26 02:48:43 +01:00
Heiner Lohaus
2360cc3330 Fix issue with old conversations 2025-01-07 00:26:01 +01:00
Heiner Lohaus
2e531d227c Fix invalid escape in requests module
Add none auth with OpenAI using nodriver
Fix missing 1 required positional argument: 'cls'
Update count tokens in GUI
Fix streaming example in requests guide
Remove ChatGptEs as default model
2025-01-06 23:20:29 +01:00
Heiner Lohaus
12c413fd2e Add Edge as Browser for nodriver
Fix for RetryProviders doesn't retry
Add retry and continue for DuckDuckGo provider
Add cache for Cloudflare provider
Add cache for prompts on gui home
Add scroll to bottom checkbox in gui
Improve prompts on home gui
Fix response content type in api for files
2025-01-05 17:02:15 +01:00
Heiner Lohaus
0d59789eed Add File API Documentation for Python and JS
Format Bucket Placeholder in GUI
2025-01-01 14:01:33 +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