Commit Graph

23 Commits

Author SHA1 Message Date
hlohaus
b6f51f00d8 refactor: restructure core utilities, typing, and request handling
- In `g4f/__init__.py`, changed logger setup to use fixed "g4f" name and refactored `ChatCompletion.create` and `create_async` to share `_prepare_request` logic for preprocessing arguments
- In `g4f/config.py`, added `__future__.annotations`, `lru_cache` import, wrapped `get_config_dir` with `@lru_cache`, and simplified platform branch logic
- In `g4f/cookies.py`, added typing imports, renamed `browsers` to `BROWSERS`, reformatted `DOMAINS`, updated docstrings, improved loop logic in `load_cookies_from_browsers` with additional exception handling, split HAR/JSON parsing into `_parse_har_file` and `_parse_json_cookie_file`, and enhanced `read_cookie_files` with optional filters and `.env` loading
- In `g4f/debug.py`, added enable/disable logging functions, updated log handler typing, appended messages to `logs` in `log()`, and improved `error()` formatting
- In `g4f/errors.py`, introduced base `G4FError` and updated all exception classes to inherit from it or relevant subclasses, with descriptive docstrings for each
- In `g4f/files.py`, added `max_length` parameter to `secure_filename`, adjusted regex formatting, and added docstring; updated `get_bucket_dir` to sanitize parts inline with docstring
- In `g4f/typing.py`, added `__future__.annotations`, reorganized imports, restricted PIL import to type-checking, defined `ContentPart` and `Message` TypedDicts, updated type aliases and `__all__` to include new types
- In `g4f/version.py`, added `lru_cache` and request timeout constant, applied caching to `get_pypi_version` and `get_github_version`, added response validation and explicit exceptions, refactored `VersionUtils.current_version` with clearer sources and error on miss, changed `check_version` to return a boolean with optional silent mode, and improved error handling outputs
2025-08-09 03:29:44 +02:00
hlohaus
b49d71db7c Auth on Cloudflare error 2025-07-15 23:43:55 +02:00
hlohaus
bf4ed09ab9 feat: Refactor extra_body handling and update model error handling
- Changed the default value of `extra_body` from an empty dictionary to `None` in `ImageLabs` and `PollinationsAI` classes.
- Added a check to initialize `extra_body` to an empty dictionary if it is `None` in the `ImageLabs` class.
- Removed the `extra_image_models` list from the `PollinationsAI` class.
- Updated the way image models are combined in the `PollinationsAI` class to avoid duplicates.
- Changed the error handling for unsupported models from `ModelNotSupportedError` to `ModelNotFoundError` in multiple classes including `OpenaiChat`, `HuggingFaceAPI`, and `HuggingFaceInference`.
- Updated the `save_response_media` function to handle both string and bytes responses.
- Adjusted the handling of audio data in the `PollinationsAI` class to ensure proper processing of audio responses.
2025-06-12 02:29:41 +02: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
ae1fae7ef0 Add chat share function 2025-03-25 01:46:57 +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
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
79c407b939 IterListProvider support for generating images (#2441)
* IterListProvider support for generating images
* Add missing get_har_files import in Copilot
* Fix typo in dall-e-3 model name
* Add image client unittests
* Add MicrosoftDesigner provider
* Import MicrosoftDesigner and add it to the model list
2024-11-29 13:56:11 +01:00
Heiner Lohaus
a4ca5773bd Fix unittests 2024-04-06 01:18:45 +02:00
Heiner Lohaus
1e2cf48cba Add authless OpenaiChat 2024-04-05 21:00:35 +02:00
H Lohaus
6ef282de3a Remove all not working provider (#1679)
Fix many providers
Add selenium-wire to requierments
2024-03-12 02:06:06 +01:00
Heiner Lohaus
eb48299195 Enable Liaobots, disable Phind provider 2024-03-08 10:12:13 +01:00
Heiner Lohaus
aba4b96f23 Add new Client API with Docs
Use object urls for the preview of image uploads.
Fix upload images in You provider
Fix create image. It's now a single image.
Improve system message for create images.
2024-02-12 11:41:27 +01:00
H Lohaus
5c75972c50 Update provider and model list (#1568)
Move bing.create_images and cookies helper
Disable some providers
2024-02-09 14:24:15 +01:00
Heiner Lohaus
c1b992c346 Add Gemini Provider with image upload and generation 2024-02-08 22:02:52 +01:00
Heiner Lohaus
47b50b4827 Fix PerplexityLabs Provider, Improve bypass_cloudflare helper 2024-01-27 02:00:44 +01:00
Heiner Lohaus
1eb7dc05e5 Fix: ChromeDriver only supports characters in the BMP
Add set_cookies helper, Show last used model
2024-01-26 12:49:52 +01:00
H Lohaus
feb83c168b New minimum requirements (#1515)
* New minimum requirements
* Add ConversationStyleOptionSets to Bing
* Add image.ImageRequest
* Improve python version support
* Improve unittests
2024-01-26 07:54:13 +01:00
Heiner Lohaus
69ef224f92 Add get_connector helper 2024-01-24 00:46:35 +01:00
Heiner Lohaus
91feb34054 Add ProviderModelMixin for model selection 2024-01-23 19:44:48 +01:00
Heiner Lohaus
cb0e065581 Remove usage of get_event_loop helper 2024-01-20 18:23:54 +01:00
Heiner Lohaus
c617b18d12 Add support for all models
Add AbstractProvider class
Add ProviderType type
Add get_last_provider function
Add version module and  VersionUtils
Display used provider in gui
Fix error response in api
2024-01-01 17:48:57 +01:00
Heiner Lohaus
d743ee0c26 Add error classes
Move version check to debug
2023-12-11 00:56:06 +01:00