Commit Graph

17 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
5bf80ec280 Catch import errors 2025-03-29 20:47:10 +01:00
kqlio67
c79635aaeb Update models and providers with improved documentation and code structure (#2786)
* docs(docs/providers-and-models.md): update documentation structure and model listings

* refactor(g4f/debug.py): add type hints and docstrings

* refactor(g4f/tools/run_tools.py): Restructure tool handling and improve modularity

* refactor(g4f/providers/response.py): enhance type hints and code documentation

* feat(g4f/models.py): Update model providers and add new models

* feat(g4f/Provider/Blackbox.py): add encrypted session handling and model updates

* fix(g4f/Provider/ChatGptEs.py): migrate to curl_cffi for request handling and improve error resilience

* feat(g4f/Provider/DeepInfraChat.py): Update default model and add new DeepSeek variants

* feat(g4f/Provider/Free2GPT.py): add Gemini models and streamline headers

* feat(g4f/Provider/FreeGpt.py): Add support for Gemini 1.5 Flash model

* feat(g4f/Provider/Liaobots.py): Add Claude 3.7 models and update default GPT-4o

* fix(g4f/Provider/PollinationsAI.py): Correct model mappings and generation parameters

* feat(g4f/Provider/PollinationsImage.py): Add class identifier label

* chore(g4f/Provider/TeachAnything.py): Update default model and simplify model handling

* (g4f/Provider/Mhystical.py): Remove class implementation

* chore(g4f/Provider/Prodia.py > g4f/Provider/not_working/Prodia.py): mark Prodia provider as non-working

* feat(g4f/Provider/Blackbox.py): Add Claude 3.7 Sonnet model alias

* chore(g4f/models.py): Update model configurations

* fix(g4f/Provider/ChatGptEs.py): improve request reliability and nonce detection

---------

Co-authored-by: kqlio67 <>
2025-03-09 19:46:27 +01:00
hlohaus
989f02fc31 Add ToolSupportProvider 2025-03-01 01:46:04 +01:00
hlohaus
e53483d85b Improve tools support in OpenaiTemplate and GeminiPro
Update models in DDG, PerplexityLabs, Gemini
Fix issues with curl_cffi in new versions
2025-02-21 04:36:54 +01:00
Heiner Lohaus
6e674ca33d Add aliases to gui arguments, fix logs variable 2024-11-19 17:25:40 +01:00
Heiner Lohaus
8f3fbee0d8 Add show log option to gui 2024-11-19 15:26:03 +01:00
Heiner Lohaus
8cc6000ffb Add Pyinstaller support, Use curl_cffi in You provider 2024-03-15 11:46:06 +01:00
Heiner Lohaus
e5b7f72b71 Move some modules, create providers dir
Set min version for duckduckgo
Make duckduckgo search async
Remove get_lastet_version
2024-02-22 00:16:58 +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
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
5a7ce3a8ab Update get_latest_version for docker 2023-12-24 20:54:10 +01:00
NiNiyas
0b2f7898d4 fix(g4f): Fix typo in function name 2023-12-19 10:38:12 +05:30
Heiner Lohaus
b2d02ed624 Change default port for gui
Change default host for api
Disable gui in build
Add custom docker user
2023-12-11 02:50:33 +01:00
Heiner Lohaus
d743ee0c26 Add error classes
Move version check to debug
2023-12-11 00:56:06 +01:00
H Lohaus
484b96d850 Add websearch to gui (#1314)
* Add websearch to gui
* Fix version_check config
* Add version badge in README.md
* Show version in gui
* Add docker hub build
* Fix gui backend, improve style
2023-12-07 07:18:05 +01:00
Heiner Lohaus
88d2cbff09 Add AiAsk, Chatgpt4Online, ChatgptDemo
and ChatgptX Provider
Fix Bing, Liaobots and ChatgptAi Provider
Add "gpt_35_long" model and custom timeout
2023-10-05 05:13:37 +02:00