Commit Graph

43 Commits

Author SHA1 Message Date
H Lohaus
0a070bdf10 feat: introduce AnyProvider & LM Arena, overhaul model/provider logic (#2925)
* feat: introduce AnyProvider & LM Arena, overhaul model/provider logic

- **Provider additions & removals**
  - Added `Provider/LMArenaProvider.py` with full async stream implementation and vision model support
  - Registered `LMArenaProvider` in `Provider/__init__.py`; removed old `hf_space/LMArenaProvider.py`
  - Created `providers/any_provider.py`; registers `AnyProvider` dynamically in `Provider`
- **Provider framework enhancements**
  - `providers/base_provider.py`
    - Added `video_models` and `audio_models` attributes
  - `providers/retry_provider.py`
    - Introduced `is_content()` helper; now treats `AudioResponse` as stream content
- **Cloudflare provider refactor**
  - `Provider/Cloudflare.py`
    - Re‑implemented `get_models()` with `read_models()` helper, `fallback_models`, robust nodriver/curl handling and model‑name cleaning
- **Other provider tweaks**
  - `Provider/Copilot.py` – removed `"reasoning"` alias and initial `setOptions` WS message
  - `Provider/PollinationsAI.py` & `PollinationsImage.py`
    - Converted `audio_models` from list to dict, adjusted usage checks and labels
  - `Provider/hf/__init__.py` – applies `model_aliases` remap before dispatch
  - `Provider/hf_space/DeepseekAI_JanusPro7b.py` – now merges media before upload
  - `needs_auth/Gemini.py` – dropped obsolete Gemini model entries
  - `needs_auth/GigaChat.py` – added lowercase `"gigachat"` alias
- **API & client updates**
  - Replaced `ProviderUtils` with new `Provider` map usage throughout API and GUI server
  - Integrated `AnyProvider` as default fallback in `g4f/client` sync & async flows
  - API endpoints now return counts of providers per model and filter by `x_ignored` header
- **GUI improvements**
  - Updated JS labels with emoji icons, provider ignore logic, model count display
- **Model registry**
  - Renamed base model `"GigaChat:latest"` ➜ `"gigachat"` in `models.py`
- **Miscellaneous**
  - Added audio/video flags to GUI provider list
  - Tightened error propagation in `retry_provider.raise_exceptions`

* Fix unittests

* fix: handle None conversation when accessing provider-specific data

- Modified `AnyProvider` class in `g4f/providers/any_provider.py`
- Updated logic to check if `conversation` is not None before accessing `provider.__name__` attribute
- Wrapped `getattr(conversation, provider.__name__, None)` block in an additional `if conversation is not None` condition
- Changed `setattr(conversation, provider.__name__, chunk)` to use `chunk.get_dict()` instead of the object directly
- Ensured consistent use of `JsonConversation` when modifying or assigning `conversation` data

* ```
feat: add provider string conversion & update IterListProvider call

- In g4f/client/__init__.py, within both Completions and AsyncCompletions, added a check to convert the provider from a string using convert_to_provider(provider) when applicable.
- In g4f/providers/any_provider.py, removed the second argument (False) from the IterListProvider constructor call in the async for loop.
```

---------

Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com>
2025-04-18 14:10:51 +02:00
hlohaus
3ab36ebc64 feat: introduce render_messages and enhance HAR/conversation handling
- **g4f/providers/helper.py**
  - Add `render_messages()` to normalise message contents that are lists of blocks.

- **g4f/Provider/Blackbox.py**
  - Import `get_har_files` and `render_messages`.
  - Replace manual walk of `get_cookies_dir()` with `get_har_files()` in `_find_session_in_har`.
  - Simplify session‑parsing loop and exception logging; drop permissions check.
  - Build `current_messages` with `render_messages(messages)` instead of raw list.

- **g4f/Provider/Cloudflare.py**
  - Swap `to_string` import for `render_messages`.
  - Add `"impersonate": "chrome"` to default `_args`.
  - Construct `data["messages"]` with `render_messages(messages)` and inline `"parts"`; remove `to_string()` calls.
  - Move `cache_file` write outside inner `try` to always save arguments.

- **g4f/Provider/Copilot.py**
  - Defer `yield conversation` until after `conversation` is created when `return_conversation` is requested.

- **g4f/Provider/openai/har_file.py**
  - Break out of `os.walk` after first directory in `get_har_files()` to avoid deep traversal.

- **g4f/api/__init__.py**
  - Use `config.conversation` directly and set `return_conversation` when present.

- **g4f/client/__init__.py**
  - Pass `conversation` to both `ChatCompletionChunk.model_construct()` and `ChatCompletion.model_construct()`.

- **g4f/client/stubs.py**
  - Import `field_serializer` (with stub fallback).
  - Add serializers for `conversation` (objects and dicts) and for `content` fields.
  - Extend model constructors to accept/propagate `conversation`.

- **g4f/cookies.py**
  - Insert ".huggingface.co" into `DOMAINS` list.
  - Stop recursive directory walk in `read_cookie_files()` with early `break`.

- **g4f/gui/client/background.html**
  - Reorder error‑handling branches; reset `errorImage` in `onload`.
  - Revise `skipRefresh` logic and random image URL building.

- **g4f/gui/server/backend_api.py**
  - Add `self.match_files` cache for repeated image searches.
  - Use `safe_search` for sanitised term matching and `min` comparison.
  - Limit walk to one directory level; support deterministic random selection via `random` query param.

- **Miscellaneous**
  - Update imports where `render_messages` replaces `to_string`.
  - Ensure all modified providers iterate messages through `render_messages` for consistent formatting.
2025-04-17 07:14:34 +02:00
hlohaus
06546649db feat: add LM Arena provider, async‑ify Copilot & surface follow‑up suggestions
* **Provider/Blackbox.py**
  * Raise `RateLimitError` when `"You have reached your request limit for the hour"` substring is detected
* **Provider/Copilot.py**
  * Convert class to `AsyncGeneratorProvider`; rename `create_completion` → `create_async_generator`
  * Swap `curl_cffi.requests.Session` for `AsyncSession`; reduce default timeout to **30 s**
  * Fully async websocket flow (`await session.ws_connect`, `await wss.send/recv/close`)
  * Emit new response types: `TitleGeneration`, `SourceLink`, aggregated `Sources`
  * Track request completion with `done` flag; collect citations in `sources` dict
* **Provider/DuckDuckGo.py**
  * Replace `duckduckgo_search.DDGS` with `duckai.DuckAI`
  * Change base class to `AbstractProvider`; drop nodriver‑based auth
* **Provider/PollinationsAI.py**
  * Re‑build text/audio model lists ensuring uniqueness; remove unused `extra_text_models`
  * Fix image seed logic (`i==1` for first retry); propagate streaming `error` field via `ResponseError`
* **Provider/hf_space**
  * **New file** `LMArenaProvider.py` implementing async queue/stream client
  * Register `LMArenaProvider` in `hf_space/__init__.py`; delete `G4F` import
* **Provider/needs_auth/CopilotAccount.py**
  * Inherit order changed to `Copilot, AsyncAuthedProvider`
  * Refactor token & cookie propagation; add `cookies_to_dict` helper
* **Provider/needs_auth/OpenaiChat.py**
  * Parse reasoning thoughts/summary; yield `Reasoning` responses
  * Tighten access‑token validation and nodriver JS evaluations (`return_by_value`)
  * Extend `Conversation` with `p` and `thoughts_summary`
* **providers/response.py**
  * Add `SourceLink` response class returning single formatted citation link
* **providers/base_provider.py**
  * Serialize `AuthResult` with custom `json.dump` to handle non‑serializable fields
  * Gracefully skip empty cache files when loading auth data
* **image/copy_images.py**
  * Ignore file extensions longer than 4 chars when inferring type
* **requests/__init__.py**
  * Use `return_by_value=True` for `navigator.userAgent` extraction
* **models.py**
  * Remove `G4F` from model provider lists; update `janus_pro_7b` best providers
* **GUI server/api.py**
  * Stream `SuggestedFollowups` to client (`"suggestions"` event)
* **GUI static assets**
  * **style.css**: bold chat title, add `.suggestions` styles, remove padding from `.chat-body`
  * **chat.v1.js**
    * Capture `suggestions` packets, render buttons, and send as quick replies
    * Re‑order finish‑reason logic; adjust token count placement and system‑prompt toggling
  * **chat-top-panel / footer** interactions updated accordingly
* **gui/client/static/js/chat.v1.js** & **css** further UI refinements (scroll handling, token counting, hide prompt toggle)
* Minor updates across multiple files to match new async interfaces and headers (`userAgent`, `raise_for_status`)
2025-04-17 01:21:58 +02:00
hlohaus
8c2c46b20f Support "Think Deeper" in Copilot
Improve Documentation
2025-03-30 15:40:46 +02:00
hlohaus
46d0b87008 Add example for video generation
Add support for images in messages
2025-03-27 09:38:31 +01:00
hlohaus
c97ba0c88e Add audio transcribing example and support
Add Grok Chat provider
Rename images parameter to media
Update demo homepage
2025-03-21 03:17:45 +01:00
kqlio67
52ecfb5019 Add new providers and enhance existing provider configurations (#2805)
* New provider added(g4f/Provider/Websim.py)

* New provider added(g4f/Provider/Dynaspark.py)

* feat(g4f/gui/client/static/js/chat.v1.js): Enhance provider labeling for HuggingFace integrations

* feat(g4f/gui/server/api.py): add Hugging Face Space compatibility flag to provider data

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

* Update g4f/Provider/__init__.py

* feat(g4f/Provider/AllenAI.py): expand model alias mappings for AllenAI provider

* feat(g4f/Provider/Blackbox.py): restructure image model handling and response processing

* feat(g4f/Provider/PollinationsAI.py): add new model aliases and streamline headers

* Update g4f/Provider/hf_space/*

* refactor(g4f/Provider/Copilot.py): update model alias mapping

* chore(g4f/models.py): update provider configurations for OpenAI models

* docs(docs/providers-and-models.md): update provider tables and model categorization

* fix(etc/examples/vision_images.py): update model and simplify client configuration

* fix(docs/providers-and-models.md): correct streaming status for GlhfChat provider

* docs(docs/providers-and-models.md): update provider capabilities and model documentation

* fix(models): update provider configurations for Mistral models

* fix(g4f/Provider/Blackbox.py): correct model alias key for Mistral variant

* feat(g4f/Provider/hf_space/CohereForAI_C4AI_Command.py): update supported model versions and aliases (close #2802)

* fix(documentation): correct model names and provider counts (https://github.com/xtekky/gpt4free/pull/2805#issuecomment-2727489835)

* fix(g4f/models.py): correct mistral model configurations

* fix(g4f/Provider/DeepInfraChat.py): correct mixtral-small alias key

* New provider added(g4f/Provider/LambdaChat.py)

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

* docs(docs/providers-and-models.md): add LambdaChat provider and update model listings

* feat(g4f/models.py): add new Liquid AI model and enhance providers

* docs(docs/providers-and-models.md): update model listings and provider counts

* feat(g4f/Provider/LambdaChat.py): add conditional reasoning processing based on model

* fix(g4f/tools/run_tools.py): handle combined thinking tags in single chunk

* New provider added(g4f/Provider/Goabror.py)

* feat(g4f/Provider/Blackbox.py): implement dynamic session management and model access control

* refactor(g4f/models.py): update provider configurations and model entries

* docs(docs/providers-and-models.md): update model listings and provider counts

---------

Co-authored-by: kqlio67 <>
2025-03-20 17:36:00 +01:00
hlohaus
b84f35f4e4 Improve model list in HuggingFace
WakeLook and disable count tokens for performance
Export and import settings in UI
Some styling improvments in UI
Fix curl_cffi updated bugs
2025-02-22 03:33:12 +01:00
hlohaus
0638cbc175 Improve select custom model in UI
Updates for the response of the BackendApi
Update of the demo model list
Improve web search tool
Moved copy_images to /image
2025-02-03 20:23:21 +01:00
hlohaus
89e096334d Support reasoning tokens by default
Add new default HuggingFace provider
Add format_image_prompt and get_last_user_message helper
Add stop_browser callable to get_nodriver function
Fix content type response in images route
2025-01-31 17:36:48 +01:00
hlohaus
2e89e5614d Raise MissingAuthError exception if access token are invalid 2025-01-30 03:13:11 +01:00
hlohaus
9524c3f327 Add AsyncAuthedProvider in Copilot
Add orginal url to downloaded image
Support ssl argument in StreamSession
Report Provider and Errors in RetryProvider
Support ssl argument in OpenaiTemplate
Remove model duplication in OpenaiChat
Disable ChatGpt provider and remove it from models.py
Update slim requirements
Support provider names as model name in Image generation
Add model qwen-2.5-1m-demo to models.py
2025-01-28 20:33:50 +01:00
hlohaus
42805ac789 Add leagcy port to docker-compose files
Update demo model list
Disable upload cookies in demo
Track usage in demo mode
Add messages without asking the ai
Add hint for browser usage in provider list
Add qwen2 prompt template to HuggingFace provider
Trim automatic messages in HuggingFaceAPI
2025-01-26 16:32:32 +01:00
hlohaus
3e1e505619 Add lock file for nodriver, add finally stop browser to all calls 2025-01-25 12:02:37 +01:00
kqlio67
9def1aa71f Update model configurations, provider implementations, and documentation (#2577)
* Update model configurations, provider implementations, and documentation

- Updated model names and aliases for Qwen QVQ 72B and Qwen 2 72B (@TheFirstNoob)
- Revised HuggingSpace class configuration, added default_image_model
- Added llama-3.2-70b alias for Llama 3.2 70B model in AutonomousAI
- Removed BlackboxCreateAgent class
- Added gpt-4o alias for Copilot model
- Moved api_key to Mhystical class attribute
- Added models property with default_model value for Free2GPT
- Simplified Jmuz class implementation
- Improved image generation and model handling in DeepInfra
- Standardized default models and removed aliases in Gemini
- Replaced model aliases with direct model list in GlhfChat (@TheFirstNoob)
- Removed trailing slash from image generation URL in PollinationsAI (https://github.com/xtekky/gpt4free/issues/2571)
- Updated llama and qwen model configurations
- Enhanced provider documentation and model details

* Removed from (g4f/models.py) 'Yqcloud' provider from Default due to error 'ResponseStatusError: Response 429: 文字过长,请删减后重试。'

* Update docs/providers-and-models.md

* refactor(g4f/Provider/DDG.py): Add error handling and rate limiting to DDG provider

- Add custom exception classes for rate limits, timeouts, and conversation limits
- Implement rate limiting with sleep between requests (0.75s minimum delay)
- Add model validation method to check supported models
- Add proper error handling for API responses with custom exceptions
- Improve session cookie handling for conversation persistence
- Clean up User-Agent string and remove redundant code
- Add proper error propagation through async generator

Breaking changes:
- New custom exceptions may require updates to error handling code
- Rate limiting affects request timing and throughput
- Model validation is now stricter

Related:
- Adds error handling similar to standard API clients
- Improves reliability and robustness of chat interactions

* Update g4f/models.py g4f/Provider/PollinationsAI.py

* Update g4f/models.py

* Restored provider which was not working and was disabled (g4f/Provider/DeepInfraChat.py)

* Fixing a bug with Streaming Completions

* Update g4f/Provider/PollinationsAI.py

* Update g4f/Provider/Blackbox.py g4f/Provider/DDG.py

* Added another model for generating images 'ImageGeneration2' to the 'Blackbox' provider

* Update docs/providers-and-models.md

* Update g4f/models.py g4f/Provider/Blackbox.py

* Added a new OIVSCode provider from the Text Models and Vision (Image Upload) model

* Update docs/providers-and-models.md

* docs: add Conversation Memory class with context handling requested by @TheFirstNoob

* Simplified README.md documentation added new docs/configuration.md documentation

* Update add README.md docs/configuration.md

* Update README.md

* Update docs/providers-and-models.md g4f/models.py g4f/Provider/PollinationsAI.py

* Added new model deepseek-r1 to Blackbox provider. @TheFirstNoob

* Fixed bugs and updated docs/providers-and-models.md etc/unittest/client.py g4f/models.py g4f/Provider/.

---------

Co-authored-by: kqlio67 <>
Co-authored-by: H Lohaus <hlohaus@users.noreply.github.com>
2025-01-24 03:47:57 +01:00
Heiner Lohaus
a57adbee97 Fix websearch with special chars 2025-01-03 21:26:20 +01:00
Heiner Lohaus
6e0bc147b5 Support continue messages in Airforce
Add auth caching for OpenAI ChatGPT
Some provider improvments
2025-01-03 20:35:46 +01:00
Heiner Lohaus
486e9a9122 Add login_url to authed providers
Create a home page for the GUI
Fix CopyButton in Code Highlight
2025-01-03 02:40:21 +01:00
Heiner Lohaus
75fe95cbed Add continue messages support,
Remove old text_to_speech service from gui
Update gui and client readmes,
Add HuggingSpaces group provider;
Add providers parameters config forms to gui
2024-12-30 02:51:36 +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
Heiner Lohaus
af677717ee Fix issue with get_cookies from nodriver in OpenaiChat 2024-12-18 02:28:26 +01:00
H Lohaus
bbb858249b Improve gradient in gui, show only models with enabled providers (#2492)
- **Cloudflare Provider**: Added error handling for missing requirements when fetching arguments.
- **Copilot Provider**: Updated the prompt formatting to use a maximum length function, improving message handling.
- **PollinationsAI Provider**: Adjusted the prompt length to a maximum of 5000 characters.
- **GitHub Copilot Provider**: Updated to use `ClientSession` for better session management.
- **CSS Updates**: Enhanced the gradient styling in the GUI for a more visually appealing interface.
- **JavaScript Updates**: Added functionality to toggle search options in the chat interface.
2024-12-17 21:17:40 +01:00
Heiner Lohaus
ff66df1486 Improved ignored providers support,
Add get_models to OpenaiAPI, HuggingFace and Groq
Add xAI provider
2024-12-15 23:22:36 +01:00
Heiner Lohaus
315a2f2595 Add streaming and system messages support in Airforce 2024-12-14 23:34:13 +01:00
H Lohaus
a591c5d409 Add Clarity Token to Copilot, (#2482)
* Add Clarity Token to Copilot,
Ignore disabled providers in gui,
Read cookie files after upload
* Add more chat templates to HuggingFace
2024-12-14 19:56:36 +01:00
H Lohaus
335c971f6a Add multiple images support (#2478)
* Add multiple images support

* Add multiple images support in gui

* Support multiple images in legacy client and in the api
Fix some model names in provider model list

* Fix unittests

* Add vision and providers docs
2024-12-13 22:20:58 +01:00
Heiner Lohaus
6a624acf55 Use custom user data dir for each provider
Reuse cookies and access token in Copilot
Send in the gui messages to multiple providers at once
Add GUI documenation
2024-12-07 19:38:04 +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
kqlio67
8d5d522c4e feat(g4f): Major provider updates and new model support (#2437)
* refactor(g4f/Provider/Airforce.py): Enhance Airforce provider with dynamic model fetching

* refactor(g4f/Provider/Blackbox.py): Enhance Blackbox AI provider configuration and streamline code

* feat(g4f/Provider/RobocodersAPI.py): Add RobocodersAPI new async chat provider

* refactor(g4f/client/__init__.py): Improve provider handling in async_generate method

* refactor(g4f/models.py): Update provider configurations for multiple models

* refactor(g4f/Provider/Blackbox.py): Streamline model configuration and improve response handling

* feat(g4f/Provider/DDG.py): Enhance model support and improve conversation handling

* refactor(g4f/Provider/Copilot.py): Enhance Copilot provider with model support

* refactor(g4f/Provider/AmigoChat.py): update models and improve code structure

* chore(g4f/Provider/not_working/AIUncensored.): move AIUncensored to not_working directory

* chore(g4f/Provider/not_working/Allyfy.py): remove Allyfy provider

* Update (g4f/Provider/not_working/AIUncensored.py g4f/Provider/not_working/__init__.py)

* refactor(g4f/Provider/ChatGptEs.py): Implement format_prompt for message handling

* refactor(g4f/Provider/Blackbox.py): Update message formatting and improve code structure

* refactor(g4f/Provider/LLMPlayground.py): Enhance text generation and error handling

* refactor(g4f/Provider/needs_auth/PollinationsAI.py): move PollinationsAI to needs_auth directory

* refactor(g4f/Provider/Liaobots.py): Update Liaobots provider models and aliases

* feat(g4f/Provider/DeepInfraChat.py): Add new DeepInfra models and aliases

* Update (g4f/Provider/__init__.py)

* Update (g4f/models.py)

* g4f/models.py

* Update g4f/models.py

* Update g4f/Provider/LLMPlayground.py

* Update (g4f/models.py g4f/Provider/Airforce.py g4f/Provider/__init__.py g4f/Provider/LLMPlayground.py)

* Update g4f/Provider/__init__.py

* Update (g4f/Provider/Airforce.py)

---------

Co-authored-by: kqlio67 <kqlio67@users.noreply.github.com>
2024-11-28 17:50:24 +01:00
Heiner Lohaus
651df0cf82 Add some arguments to chat completion api, update discord links 2024-11-27 14:44:24 +01:00
Heiner Lohaus
4ae3d98df8 Sort .har files by date, filter None from result 2024-11-26 19:28:41 +01:00
Heiner Lohaus
46038c6a20 Add .har file support for Copilot
Update provider in Vision documentation
Hide
2024-11-25 13:27:56 +01:00
H Lohaus
431db7b8ea Update api / add a synthesize and upload_cookies endpoint (#2406)
* Add web_search function to OpenaiChat provider
* GithubCopilot provider added, it need a api_key
* Remove nodriver login in Gemini synthesize

* Update api / add a synthesize and upload_cookies endpoint
2024-11-23 00:17:35 +01:00
H Lohaus
ffb4b0d162 Improve download of generated images, serve images in the api (#2391)
* Improve download of generated images, serve images in the api
Add support for conversation handling in the api

* Add orginal prompt to image response

* Add download images option in gui, fix loading model list in Airforce

* Add download images option in gui, fix loading model list in Airforce
2024-11-20 19:58:16 +01:00
Heiner Lohaus
58fa409eef Add Cerebras and HuggingFace2 provider, Fix RubiksAI provider
Add support for image generation in Copilot provider
2024-11-20 02:34:47 +01:00
Heiner Lohaus
1fe59623b2 Add image upload to Copilot provider
Add --cookie-browsers argument to cli
2024-11-19 20:26:00 +01:00
Heiner Lohaus
8f3fbee0d8 Add show log option to gui 2024-11-19 15:26:03 +01:00
Heiner Lohaus
c3103164ce Add image upload to Copilot provider 2024-11-19 11:03:50 +01:00
Heiner Lohaus
b79a4d6aeb Ask for auth on image upload 2024-11-19 10:39:22 +01:00
Heiner Lohaus
7c10a036ed Add image upload to Copilot provider
Remove prompt lock from gui
Fix discord link in gui
2024-11-19 10:23:24 +01:00
Heiner Lohaus
2fe43166cc Update unittests 2024-11-18 18:23:16 +01:00
Heiner Lohaus
8bc456f3b6 Add account support in Copilot provider 2024-11-18 17:53:15 +01:00
Heiner Lohaus
f1ef23285a Fix load model list i AirforceChat provider
Add Microsoft Copilot provider
Show image support in the model list of the gui
2024-11-18 15:41:45 +01:00