Commit Graph

33 Commits

Author SHA1 Message Date
hlohaus
dbef5facb6 Update providers 2025-06-15 11:03:49 +02:00
hlohaus
1f5bfe5053 Disable retries in LegacyLMArena 2025-06-15 08:33:21 +02:00
hlohaus
e9179b87c2 feat: add ffmpeg and flac installation to Dockerfiles
- Updated `Dockerfile` to install `ffmpeg` and `flac` along with existing packages.
- Updated `Dockerfile-slim` to install `ffmpeg` and `flac` along with existing packages.
- Modified `any_provider.py` to change how providers are handled when a model is specified, allowing for a submodel to be extracted and checked against the provider's attributes.
- Adjusted `retry_provider.py` to ensure the alias for the model is correctly set based on the provider's model aliases, improving clarity in debug logging.
2025-06-13 10:37:12 +02:00
hlohaus
c12227a1cd fix: enhance retry logic and parameter handling in commit and provider code
- Added `--max-retries` argument to `parse_arguments()` in `commit.py` with default `MAX_RETRIES`
- Updated `generate_commit_message()` to accept a `max_retries` parameter and iterate accordingly
- Included check to raise immediately if `max_retries` is 1 within `generate_commit_message()`
- Passed `args.max_retries` when calling `generate_commit_message()` in `main()`
- In `g4f/Provider/har/__init__.py`, imported `ResponseError` and added check for network error to raise `ResponseError`
- In `g4f/Provider/hf_space/Qwen_Qwen_3.py`, changed default model string and updated system prompt handling to use `get_system_prompt()`
- In `g4f/Provider/needs_auth/LMArenaBeta.py`, modified callback to wait for cookie and turnstile response
- In `g4f/Provider/needs_auth/PuterJS.py`, adjusted `get_models()` to filter out certain models
- In `g4f/gui/server/api.py`, adjusted `get_model_data()` to handle models starting with "openrouter:"
- In `g4f/providers/any_provider.py`, imported and used `ResponseError`; added logic to process `model_aliases` with updated model name resolution
- Refined model name cleaning logic to handle additional patterns and replaced multiple regex patterns to better match version strings
- Updated list of providers `PROVIERS_LIST_1`, `PROVIERS_LIST_2`, `PROVIERS_LIST_3`, and their usage to include new providers and adjust filtering
- In `g4f/version.py`, added `get_git_version()` function, retrieved version with `git describe` command, instead of only relying on `get_github_version()`, increasing robustness
2025-06-13 05:32:55 +02:00
hlohaus
963c3a585e refactor: Refactor image generation parameters handling
- Updated the `PollinationsAI` class in `g4f/Provider/PollinationsAI.py`:
  - Changed `aspect_ratio` parameter handling to conditionally use default "1:1" if not specified.
  - Enhanced media handling by introducing `media` parameter in `_generate_image` method.
  - Updated parameter processing in `_generate_image_async` method for `model == "gptimage"`.

- Updated `Api` class in `g4f/api/__init__.py`:
  - Simplified handling of `credentials` for `config.api_key`.

- Updated `Images` class in `g4f/client/__init__.py`:
  - Added `download_media` parameter to `_process_image_response` method.
  - Enhanced `_process_image_response` method to conditionally download media based on `download_media` flag.

- Updated `_process_image_response` method in `Images` class in `g4f/client/__init__.py`:
  - Enhanced handling of media response based on `download_media` flag.

- Updated `is_valid_media` function in `g4f/image/__init__.py`:
  - Added typing annotations for clarity.

- Updated `AnyProvider` class in `g4f/providers/any_provider.py`:
  - Improved handling of `api_key` dictionary to set `extra_body["api_key"]`.

- Updated `IterListProvider` class in `g4f/providers/retry_provider.py`:
  - Enhanced handling of `model` and `api_key` parameters.

- Updated `BaseProvider` class in `g4f/providers/types.py`:
  - Added `create_function` and `async_create_function` methods.

- Updated `BaseRetryProvider` class in `g4f/providers/types.py`:
  - Enhanced handling of `model` and `api_key` parameters in provider iteration.
2025-06-12 14:23:04 +02:00
hlohaus
2befef988b feat: refactor provider create functions to class attributes and update calls
- Added `create_function` and `async_create_function` class attributes with default implementations in `base_provider.py` for `AbstractProvider`, `AsyncProvider`, and `AsyncGeneratorProvider`
- Updated `get_create_function` and `get_async_create_function` methods to return these class attributes
- Replaced calls to `provider.get_create_function()` and `provider.get_async_create_function()` with direct attribute access `provider.create_function` and `provider.async_create_function` across `g4f/__init__.py`, `g4f/client/__init__.py`, `g4f/providers/retry_provider.py`, and `g4f/tools/run_tools.py`
- Removed redundant `get_create_function` and `get_async_create_function` methods from `providers/base_provider.py` and `providers/types.py`
- Ensured all provider response calls now use the class attributes for creating completions asynchronously and synchronously as needed
2025-06-12 12:45:55 +02:00
hlohaus
7b4de3a86c Revert models.py 2025-05-31 11:34:38 +02:00
hlohaus
57cbd55d74 feat: integrate Pollinations AI enhancements and simplify gpt4free references
- Replaced the large GitHub project stats table in `README.md` with summaries and logos for Pollinations AI and MoneyPrinter V2
- Introduced `STATIC_URL` and `DIST_DIR` constants in new `g4f/constants.py` and used them across multiple files
- Updated `PollinationsAI.py` to support conversation title and follow-up generation using tool calls
- Modified `PollinationsAI.py` and `PollinationsImage.py` to use `STATIC_URL` for the `referrer` header
- Enhanced `PollinationsAI.stream_complete` to yield `ToolCalls`, `TitleGeneration`, and `SuggestedFollowups`
- Added `ToolCalls` handling in `client/__init__.py` to support non-stream and stream modes
- Updated `ChatCompletionDelta` model in `client/stubs.py` to support `ToolCalls`
- Modified `HarProvider` to merge `DEFAULT_HEADERS` into request headers
- Improved `OpenaiChat.py` by adding optional chaining to page evaluation expressions for robustness
- Updated `any_provider.py` to force use of `PollinationsAI` if `tools` key is present in kwargs
- Refactored `is_content` into a reusable function in `providers/response.py` and used in `retry_provider.py`
- Updated `gui/server/website.py` to use `STATIC_URL` and simplify `GPT4FREE_URL` handling
- Removed redundant constants from `version.py` and imported them from `constants.py
2025-05-18 01:54:09 +02:00
hlohaus
3775c1e06d fix: improve error handling and add type checks in various providers and API
- Updated error handling in g4f/Provider/DDG.py to raise ResponseError instead of yield error strings
- Replaced yield statements with raises in g4f/Provider/DDG.py for HTTP and response errors
- Added response raising in g4f/Provider/DeepInfraChat.py for image upload responses
- Included model alias validation and error raising in g4f/Provider/hf/HuggingFaceMedia.py
- Corrected model alias dictionary key in g4f/Provider/hf_space/StabilityAI_SD35Large.py
- Ensured referrer parameter default value in g4f/Provider/PollinationsImage.py
- Removed duplicate imports and adjusted get_models method in g4f/Provider/har/__init__.py
- Modified g4f/gui/server/api.py to remove unused conversation parameter in _create_response_stream
- Fixed logic to handle single exception in g4f/providers/retry_provider.py
- Added missing import of JsonConversation in g4f/providers/retry_provider.py
- Corrected stream_read_files to replace extension in return string in g4f/tools/files.py
2025-05-17 10:02:13 +02:00
hlohaus
93986d15f6 fix: resolve model duplication and improve provider handling
- Fixed duplicate model entries in Blackbox provider model_aliases
- Added meta-llama- to llama- name cleaning in Cloudflare provider
- Enhanced PollinationsAI provider with improved vision model detection
- Added reasoning support to PollinationsAI provider
- Fixed HuggingChat authentication to include headers and impersonate
- Removed unused max_inputs_length parameter from HuggingFaceAPI
- Renamed extra_data to extra_body for consistency across providers
- Added Puter provider with grouped model support
- Enhanced AnyProvider with grouped model display and better model organization
- Fixed model cleaning in AnyProvider to handle more model name variations
- Added api_key handling for HuggingFace providers in AnyProvider
- Added see_stream helper function to parse event streams
- Updated GUI server to handle JsonConversation properly
- Fixed aspect ratio handling in image generation functions
- Added ResponsesConfig and ClientResponse for new API endpoint
- Updated requirements to include markitdown
2025-05-16 00:18:12 +02:00
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
e76e5f7835 Use dynamtic aspect_ratio for image and video size 2025-03-23 14:47:26 +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
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
H Lohaus
8909ca9937 Update retry_provider.py 2025-01-29 08:53:22 +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
Heiner Lohaus
2e531d227c Fix invalid escape in requests module
Add none auth with OpenAI using nodriver
Fix missing 1 required positional argument: 'cls'
Update count tokens in GUI
Fix streaming example in requests guide
Remove ChatGptEs as default model
2025-01-06 23:20:29 +01:00
Heiner Lohaus
12c413fd2e Add Edge as Browser for nodriver
Fix for RetryProviders doesn't retry
Add retry and continue for DuckDuckGo provider
Add cache for Cloudflare provider
Add cache for prompts on gui home
Add scroll to bottom checkbox in gui
Improve prompts on home gui
Fix response content type in api for files
2025-01-05 17:02:15 +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
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
H Lohaus
3f93d34cbf Add more contributers, add link to Swagger UI (#2443)
* Add more contributers, add link to Swagger UI
* Update Dockerfile-slim
* Update retry_provider.py
* Add html preview to gui, fix urls in website manifest
* Missing chunks in OpenaiChat
2024-11-30 22:11:18 +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
c31f5435c4 Fix api with default providers, add unittests for RetryProvider 2024-11-28 17:46:46 +01:00
H Lohaus
fe0ab0427e Fix api requests with retry provider 2024-11-28 10:42:14 +01:00
Heiner Lohaus
1994481872 Update model list / providers 2024-05-19 05:09:55 +02:00
Heiner Lohaus
24c5502d76 Add needs auth to provierds, Add PerplexityApi provider
Add proxy support to nodriver
2024-05-15 21:07:49 +02:00
Heiner Lohaus
59fcf9d2d3 Update chatgpt url, uvloop support 2024-05-15 02:27:51 +02:00
abc
f57af704ba update retryprovider
now works with one provider.
2024-04-12 22:29:43 +01:00
Heiner Lohaus
84812b9632 Update some providers
Improve read access_token in OpenaiChat
Add IterProvider
Add system message support in FlowGpt
Filter none values in new Client
2024-02-27 11:55:40 +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