Commit Graph

177 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
819f4d85ae fix: update timeout, regex, and message logic in OpenaiChat & chat.v1.js
- **g4f/Provider/needs_auth/OpenaiChat.py:**
  - Increase the default timeout parameter from 180 to 360 seconds.
  - Modify the regex pattern used in `re.sub` from
    `(?:cite\nturn[0-9]+search|cite\nturn[0-9]+news|turn[0-9]+news|turn[0-9]+search)(\d+)`
    to
    `(?:cite\nturn[0-9]+|turn[0-9]+)(?:search|news|view)(\d+)`.
- **g4f/gui/client/static/js/chat.v1.js:**
  - Change the `filter_message` function to wrap the result of `text.replaceAll(...)` with `filter_message_content`, removing the chained `.replace` calls.
  - In `add_message_chunk`, update the `update_message` call by passing `null` instead of the rendered reasoning.
  - In `update_message`, refine the content-building logic by:
    - Checking that both `reasoning_storage[message_id]` and `message_storage[message_id]` exist before concatenating rendered reasoning with the markdown-rendered message.
    - Using an alternative branch to render only the reasoning when no message content is available.
    - Appending an error message (if one exists) to the content and then updating `content_map.inner.innerHTML` unconditionally.
2025-04-17 03:28:07 +02:00
hlohaus
90ef870345 fix: update provider integrations, recipient logic, and auth handling
- In **FreeRouter.py**, change the `working` flag from `False` to `True`.
- In **LMArenaProvider.py**, replace the `.rstrip("▌")` call with a manual check that, if the content ends with `▌`, slices off the trailing characters.
- In **hf_space/__init__.py**, update the async generator call to pass the `media` parameter instead of `images`.
- In **OpenaiChat.py**:
  - Modify the citation replacement regex to use `[0-9]+` (supporting any turn number) instead of a hardcoded `0`.
  - Replace `fields.is_recipient` boolean checks with comparisons against `fields.recipient == "all"` for processing text and metadata.
  - Add a new branch to process `/message/metadata/content_references` for adding source links.
  - Update the conversation initialization by replacing `self.is_recipient` with setting `self.recipient` to `"all"`.
  - Change the auth check from using `cls._api_key` to checking `cls.request_config.access_token`.
- In **chat.v1.js**, adjust the QR code URL assignment to use `window.conversation_id` if available, else default to `/qrcode`.
- In **raise_for_status.py**, update error handling by replacing `ResponseStatusError` with `MissingAuthError` for 403 responses detected as OpenAI Bot.
2025-04-17 03:26:50 +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
323765d810 ```
feat: add private chat mode & update token parsing

- In g4f/Provider/Blackbox.py, import PaymentRequiredError and raise it when the response equals "You have reached your request limit for the hour".
- In g4f/Provider/needs_auth/OpenaiChat.py, modify token parsing by splitting the "OpenAI-Sentinel-Proof-Token" header on "~" after the initial split.
- In g4f/gui/client/index.html, add a new "Private Conversation" button with the corresponding icon.
- In g4f/gui/client/static/js/chat.v1.js:
  - Introduce the variable `privateConversation` to handle private chats.
  - Update `new_conversation` to accept a private flag, setting `window.conversation_id` to null and updating the conversation title accordingly.
  - Adjust `get_conversation` to return `privateConversation` when conversation_id is null.
  - Revise `save_conversation` and `add_conversation` to store private conversation data when conversation_id is null.
  - Modify on-load conversation handling to incorporate the updated conversation logic.
```
2025-04-16 16:01:02 +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
d38755b42a Code review changes 2025-03-30 17:57:42 +02:00
hlohaus
8c2c46b20f Support "Think Deeper" in Copilot
Improve Documentation
2025-03-30 15:40:46 +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
7db18c2a2f Insert buckets as content part
Fix copy button for code results
Use crypto for uuids in UI
2025-03-28 12:17:10 +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
344034fe23 Fix unittests 2025-03-26 13:30:15 +01:00
hlohaus
ce500f0d49 Set default model in HuggingFaceMedia
Improve handling of shared chats
Show api_key input if required
2025-03-26 01:32:05 +01:00
hlohaus
41abdf71aa Remove reasoning ticker 2025-03-25 12:52:24 +01:00
hlohaus
13810b8ae0 Use loading icon 2025-03-25 11:55:29 +01:00
hlohaus
e1aa465356 Add autoplay to videos 2025-03-25 07:40:29 +01:00
hlohaus
142e4876ae Add background page 2025-03-25 04:32:11 +01:00
hlohaus
f723e92a23 Limit URL length for PollinationsAI 2025-03-25 02:29:53 +01:00
hlohaus
ae1fae7ef0 Add chat share function 2025-03-25 01:46:57 +01:00
hlohaus
ff365ff55c Update mobile template in UI 2025-03-24 11:11:53 +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
8f6efd5366 Update docs: Using the OpenAI Library
Add sse function to requests sessions
Small improvments in OpenaiChat and ARTA provider
2025-03-22 07:32:30 +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
H Lohaus
237ee94878 Update chat.v1.js 2025-03-12 07:47:22 +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
ad59df3011 Fix track usage 2025-03-10 05:21:20 +01:00
hlohaus
2799bf728c Show Audio, hide YouTube response 2025-03-10 01:40:39 +01:00
hlohaus
14817cdd66 Audio model support in PollinationsAI
Allow Fullscreen for Youtube in Gemini
2025-03-06 23:19:57 +01:00
hlohaus
23814d3c8c Hide request login in api
Add Grok provider
Update liaobots provider
2025-03-04 16:58:41 +01:00
hlohaus
4e12f048b1 Add langchain integration 2025-02-27 12:25:41 +01:00
hlohaus
1d3a139a53 Add new media selection in UI
Add HuggingFace provider provider
Auto refresh Google Gemini cookies
Add sources to search results
2025-02-26 11:41:00 +01:00
hlohaus
ee9e0c3826 Add Gemini provider to Demo 2025-02-24 15:50:50 +01:00
hlohaus
5cbbe2fd3d Fix model and provider in chat completion response
Add login button to HuggingFace demo
Custom conversation ids in chat ui
Remove rate limiter in demo mode
Improve YouTube support in Gemini
2025-02-24 08:53:43 +01:00
hlohaus
6314d27dc4 Fix url download function 2025-02-22 14:20:54 +01:00
hlohaus
6ba21db0bb Fix typos 2025-02-22 13:54:33 +01:00
hlohaus
ba60296677 Fix unittest, update model lists 2025-02-22 13:19:52 +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
470b795418 Show only free providers by default 2025-02-21 06:52:04 +01:00
hlohaus
226c69da93 Improve styling mobile 2025-02-11 18:58:53 +01:00
H Lohaus
34b815b38e Merge pull request #2705 from kqlio67/main
Updated Blackbox/CablyAI/PollinationsAI provider
2025-02-10 21:36:16 +01:00
kqlio67
bd8071b3ed feat(g4f/gui/client/static/js/chat.v1.js): enhance sidebar interactions 2025-02-10 22:33:47 +02:00
hlohaus
2d6ce560d4 Fix issue with demo mode
Fix issue with share API
2025-02-08 18:35:05 +01:00
hlohaus
ad5d09fbbe Fix show new Window Button 2025-02-07 13:13:09 +01:00
hlohaus
035daa225b Add FluxDev to G4F provider
Improve image preview in FluxDev
Add zerogpu_token to FluxDev
Add HuggingSpace header in Demo
Add new window button in Demo
2025-02-06 21:24:59 +01:00
hlohaus
9994bb67a1 Add zerogpu_uuid to demo 2025-02-05 17:07:20 +01:00