Commit Graph

71 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
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
03e37e0bee refactor: update string conversion, provider aliases, and model mappings
- In **g4f/Provider/Cloudflare.py**:
  - Added `from .helper import to_string`.
  - Replaced conditional string checks with `to_string(message["content"])` for both `"content"` and elements in `"parts"`.

- In **g4f/Provider/PollinationsAI.py**:
  - Removed `"o3-mini"` from the `vision_models` list.
  - Updated the alias mapping dictionary by:
    - Removing the `"o3-mini": "openai-reasoning"` entry.
    - Removing the duplicate `"gpt-4o-mini": "searchgpt"` mapping.
    - Removing the duplicate `"gemini-2.0-flash-thinking": "gemini-reasoning"` entry.
    - Removing the `"qwq-32b": "qwen-reasoning"` mapping.
    - Adding a new alias `"llama-4-scout": "llamascout"`.

- In **g4f/gui/client/static/css/style.css**:
  - Changed the `border-left` property value from `var(--colour-4)` to `var(--media-select)`.

- In **g4f/models.py**:
  - For the `"o3-mini"` model, removed `PollinationsAI` from its `best_provider` list.
  - Changed the comment from `# llama 2` to `### llama 2-4 ###` and removed redundant comments for llama 3.1 and 3.2.
  - Added a new model `llama_4_scout` with `base_provider` set to `"Meta Llama"` and `best_provider` as `IterListProvider([Cloudflare, PollinationsAI])`.
  - For the `"qwq-32b"` model, removed `PollinationsAI` from its `best_provider` list.
  - Updated the `ModelUtils` mapping to include the new `llama_4_scout` model.
2025-04-16 14:43:57 +02:00
kqlio67
0e78f74a17 Fix conflict g4f/Provider/PollinationsAI.py 2025-04-06 10:33:21 +03:00
hlohaus
2234d926b8 Fix "n" parameter in API, update models.py 2025-04-05 16:03:28 +02:00
kqlio67
54ef1a511c docs: update providers documentation and enhance support for Blackbox HAR auth
- Added "No auth / HAR file" authentication type in providers-and-models.md
- Added "Video generation" column to provider tables for future capability
- Updated model counts and provider capabilities throughout documentation
- Fixed ARTA provider with improved error handling and response validation
- Enhanced AllenAI provider with vision model support and proper image handling
- Significantly improved Blackbox provider:
  - Added HAR file authentication support
  - Added subscription status checking
  - Added premium/demo model differentiation
  - Improved session handling and error recovery
- Enhanced DDG provider with better error handling for challenges
- Improved PollinationsAI and PollinationsImage providers' model handling
- Added VideoModel class in g4f/models.py
- Added audio/video generation indicators in GUI components
- Added new Ai2 models: olmo-1-7b, olmo-2-32b, olmo-4-synthetic
- Added new commit message generation tool in etc/tool/commit.py
2025-04-04 13:36:28 +03:00
hlohaus
7a75782af3 Add headers / styling from in UI @kqlio67 2025-03-31 15:21:30 +02:00
hlohaus
714d02006e Fix unittests 2025-03-29 20:56:09 +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
a1871dafeb Improve background page
Improve share js functions
Fix photoswipe in UI
Support n parameter in PollinationsAI
2025-03-26 21:39:19 +01:00
hlohaus
d17305ab5e Add video feed to background site 2025-03-26 04:17:16 +01:00
hlohaus
13810b8ae0 Use loading icon 2025-03-25 11:55:29 +01:00
hlohaus
f723e92a23 Limit URL length for PollinationsAI 2025-03-25 02:29:53 +01:00
hlohaus
5ae71adbae Small changes 2025-03-24 11:35:41 +01:00
hlohaus
e76e5f7835 Use dynamtic aspect_ratio for image and video size 2025-03-23 14:47:26 +01:00
hlohaus
8eaaf5db95 Add HuggingFaceMedia provider with Video Generation
Add Support for Video Response in UI
Improve Support for Audio Response in UI
Fix ModelNotSupported errors in HuggingSpace providers
2025-03-23 05:27:52 +01:00
hlohaus
fa2344b031 Update openai example in docs, add default api_key 2025-03-21 06:22:38 +01:00
hlohaus
705ad02954 Add audio example usage 2025-03-21 05:13:59 +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
a839900392 Enable streaming in PollinationsAI 2025-03-13 08:07:27 +01:00
hlohaus
a021dcdfc6 Update model list in PollinationsAI
Update config parameters
2025-03-12 14:58:06 +01:00
H Lohaus
a2f609b540 Update PollinationsAI.py 2025-03-12 09:09:41 +01:00
hlohaus
713ad2c83c Add many parameters to API endpoints
Support conversational HuggingFace providers
Fix streaming in PollinationsAI provider
2025-03-11 22:16:03 +01:00
hlohaus
3e7af90949 Add ARTA image provider
Add ToolSupport in PollinationsAI provider
Add default value for model in chat completions
Add Streaming Support for PollinationsAI provider
2025-03-11 02:49:24 +01:00
hlohaus
6f07ce4525 Update PollinationsAI provider 2025-03-10 03:52:26 +01:00
hlohaus
2799bf728c Show Audio, hide YouTube response 2025-03-10 01:40:39 +01:00
kqlio67
ce2692565c Add Audio Generation and Response Support for AI Providers (#2788)
* feat(g4f/providers/response.py): add audio response support

* feat(g4f/Provider/PollinationsAI.py): add audio generation support and enhance model handling

* fix(g4f/providers/response.py): remove duplicate Audio class definition

---------

Co-authored-by: kqlio67 <>
2025-03-09 21:21:09 +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
14817cdd66 Audio model support in PollinationsAI
Allow Fullscreen for Youtube in Gemini
2025-03-06 23:19:57 +01:00
hlohaus
989f02fc31 Add ToolSupportProvider 2025-03-01 01:46:04 +01:00
hlohaus
510d9d9bcd Add LangChain Documenation Example 2025-02-28 00:14:29 +01:00
hlohaus
791b9f5c5a Add default llama 3 model 2025-02-27 18:47:48 +01:00
hlohaus
4e12f048b1 Add langchain integration 2025-02-27 12:25:41 +01:00
kqlio67
07a8dfdff7 AI Provider and Model Updates: Adding New, Removing Deprecated, and Enhancing Functionality (#2739)
* docs(docs/providers-and-models.md): Update provider listings and model information

* feat(g4f/models.py): update model configurations and expand provider support

* fix(g4f/gui/client/static/js/chat.v1.js): correct provider checkbox initialization logic

* feat(g4f/Provider/Blackbox.py): update model configurations and premium handling

* feat(g4f/Provider/ChatGLM.py): add finish reason handling and update default model

* chore(g4f/Provider/DDG.py): Reorder model entries for consistency

* feat(g4f/Provider/ImageLabs.py): Update default image model to sdxl-turbo

* feat(g4f/Provider/Liaobots.py): update supported model configurations and aliases

* feat(g4f/Provider/OIVSCode.py): Update API endpoint and expand model support

* fix(g4f/Provider/needs_auth/CablyAI.py): Enforce authentication requirement

* Removed the provider (g4f/Provider/BlackboxAPI.py)

* fix(g4f/providers/base_provider.py): improve cache validation in AsyncAuthedProvider

* Update g4f/models.py

* fix(g4f/Provider/Liaobots.py): remove deprecated Gemini model aliases

* chore(g4f/models.py): Remove Grok-2 and update Gemini provider configurations

* chore(docs/providers-and-models.md): Remove deprecated Grok models from provider listings

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

* feat(g4f/models.py): Add Ai2 models and update provider references

* feat(docs/providers-and-models.md): update providers and models documentation

* fix(g4f/models.py): update experimental model provider configuration

* fix(g4f/Provider/PollinationsImage.py): Initialize image_models list and update label

* fix(g4f/Provider/PollinationsAI.py): Resolve model initialization and alias conflicts

* refactor(g4f/Provider/PollinationsAI.py): improve model initialization and error handling

* refactor(g4f/Provider/PollinationsImage.py): Improve model synchronization and initialization

* Update g4f/Provider/AllenAI.py

---------

Co-authored-by: kqlio67 <>
2025-02-24 15:53:20 +01:00
hlohaus
ba60296677 Fix unittest, update model lists 2025-02-22 13:19:52 +01:00
hlohaus
470b795418 Show only free providers by default 2025-02-21 06:52: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
kqlio67
b1de624963 fix(g4f/Provider/PollinationsAI.py): Remove duplicate model alias 2025-02-10 19:50:35 +02:00
kqlio67
21eecea02f Optimization and bug fixes for PollinationsAI provider: improved error handling, model validation, and HTTP request processing 2025-02-07 16:50:35 +02:00
kqlio67
88e7ef98f0 Adding New Models and Enhancing Provider Functionality (#2689)
* Adding New Models and Enhancing Provider Functionality

* fix(core): handle model errors and improve configuration

- Import ModelNotSupportedError for proper exception handling in model resolution
- Update login_url configuration to reference class URL attribute dynamically
- Remove redundant typing imports after internal module reorganization

* feat(g4f/Provider/PerplexityLabs.py): Add new Perplexity models and update provider listings

- Update PerplexityLabs provider with expanded Sonar model family including pro/reasoning variants
- Add new text models: sonar-reasoning-pro to supported model catalog
- Standardize model naming conventions across provider documentation

* feat(g4f/models.py): add Sonar Reasoning Pro model configuration

- Add new  model to Perplexity AI text models section
- Include model in ModelUtils.convert mapping with PerplexityLabs provider
- Maintain consistent configuration pattern with existing Sonar variants

* feat(docs/providers-and-models.md): update provider models and add new reasoning model

- Update PerplexityLabs text models to standardized sonar naming convention
- Add new sonar-reasoning-pro model to text models table
- Include latest Perplexity AI documentation references for new model

* docs(docs/providers-and-models.md): update AI providers documentation

- Remove deprecated chatgptt.me from no-auth providers list
- Delete redundant Auth column from HuggingSpace providers table
- Update PerplexityLabs model website URLs to sonar.perplexity.ai
- Adjust provider counts for GPT-4/GPT-4o models in text models section
- Fix inconsistent formatting in image models provider listings

* chore(g4f/models.py): remove deprecated ChatGptt provider integration

- Remove ChatGptt import from provider dependencies
- Exclude ChatGptt from default model's best_provider list
- Update gpt_4 model configuration to eliminate ChatGptt reference
- Modify gpt_4o vision model provider hierarchy
- Adjust gpt_4o_mini provider selection parameters

BREAKING CHANGE: Existing integrations using ChatGptt provider will no longer function

* Disabled provider (g4f/Provider/ChatGptt.py > g4f/Provider/not_working/ChatGptt.py): Problem with Cloudflare

* fix(g4f/Provider/CablyAI.py): update API endpoints and model configurations

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

* feat(g4f/models.py): Add Hermes-3 model and enhance provider configs

* feat(g4f/Provider/CablyAI.py): Add free tier indicators to model aliases

* refactor(g4f/tools/run_tools.py): modularize thinking chunk handling

* fix(g4f/Provider/DeepInfraChat.py): resolve duplicate keys and enhance request headers

* feat(g4f/Provider/DeepInfraChat.py): Add multimodal image support and improve model handling

* chore(g4f/models.py): update default vision model providers

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

* Update docs/client.md

* docs(docs/providers-and-models.md): Update DeepInfraChat models documentation

* feat(g4f/Provider/DeepInfraChat.py): add new vision models and expand model aliases

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

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

---------

Co-authored-by: kqlio67 <>
2025-02-07 13:54:00 +01:00
hlohaus
03d0c3053f Add mew G4F provider 2025-02-05 01:29:11 +01:00
hlohaus
c4e4d340c4 Update PollinationsImage provider 2025-02-04 16:46:30 +01:00
hlohaus
1d00be5b91 Fix api_key in HuggingFace provider
Split PollinationsAI provider in two provider
Update model list in CablyAI
Return backup url, if copy images failed
Update url for logging in UI
2025-02-04 16:25:51 +01:00
H Lohaus
62ed2e394e Merge branch 'main' into New 2025-02-02 23:31:53 +01:00
hlohaus
167ceedd31 Update model list in OpenaiChat (o3-mini, o3-mini-high)
Add Reasoning to OpenaiChat provider
Check for pipeline_tag in HuggingChat providers
Add image preview in PollinationsAI
Add input of custom Model in GUI
2025-02-02 23:03:59 +01:00
kqlio67
3b091647fa Added new models and providers, improved interface components, improved providers (#2646)
* Fix conflict g4f/gui/client/static/css/style.css g4f/gui/client/static/js/chat.v1.js g4f/models.py g4f/Provider/.

* Update g4f/Provider/Blackbox.py

* Update g4f/Provider/PollinationsAI.py

* Update docs/providers-and-models.md

* Disabled provider 'AIUncensored'

* Two providers 'AIChatFree, AutonomousAI' are disabled

---------

Co-authored-by: kqlio67 <>
2025-02-01 00:49:08 +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
2c895831b1 Fix unittests, set strategy for rate limter 2025-01-28 21:25:26 +01:00