Commit graph

42 commits

Author SHA1 Message Date
hlohaus
1edd0fff17 Refactor model handling and improve timeout functionality
- Removed empty string mapping from model_map in AnyModelProviderMixin.
- Updated clean_name function to exclude 'chat' from version patterns.
- Added stream_timeout parameter to AsyncGeneratorProvider for more flexible timeout handling.
- Enhanced chunk yielding in AsyncAuthedProvider to support stream_timeout, allowing for better control over asynchronous responses.
2025-09-04 18:11:05 +02:00
kqlio67
9bac34fc88 refactor: reorganize providers and update model configurations
- Rename DeepInfraChat to DeepInfra across all files
- Move DeepInfra from needs_auth to main Provider directory
- Rename LMArenaBeta to LMArena throughout codebase
- Move search-related providers to new search subdirectory (GoogleSearch, SearXNG, YouTube)
- Move deprecated providers to not_working directory (Free2GPT, LegacyLMArena, PenguinAI, ImageLabs, har)
- Add new Mintlify provider with custom AI assistant implementation
- Update Anthropic provider with Claude 4 models and Opus 4.1 parameter handling
- Update Grok provider with Grok 4 models and improved streaming support
- Update GithubCopilot with expanded model list including o3-mini, o4-mini, gpt-5 previews
- Update LambdaChat default model from deepseek-r1 to deepseek-llama3.3-70b
- Update TeachAnything default model from gemini-1.5-pro to gemma
- Remove DeepInfra from needs_auth directory
- Update all model_map references from DeepInfraChat to DeepInfra
- Update all model_map references from LMArenaBeta to LMArena
- Add beta_headers support to Anthropic for special features
- Improve Mintlify provider with system prompt handling and streaming
- Update model configurations in models.py to reflect provider changes
2025-08-25 23:50:53 +03:00
hlohaus
05f0f55711 refactor: update providers list, env vars, and minor fixes
- **example.env**:
  - Added `G4F_API_KEY` and `G4F_PROXY` variables
  - Removed Azure-related API keys and routes block
  - Added `OLLAMA_API_KEY`, `NVIDIA_API_KEY`, and `PUTER_API_KEY`

- **g4f/Provider/EasyChat.py**:
  - Replaced `page.js_dumps` with `page.evaluate` for retrieving `guestId`

- **g4f/Provider/deprecated/LegacyLMArena.py**:
  - Changed `working = True` to `working = False`

- **g4f/Provider/deprecated/har/__init__.py**:
  - Changed `working = True` to `working = False`

- **g4f/providers/any_provider.py**:
  - Updated imports, adding `Custom`, `PollinationsImage`, `OpenaiAccount`, and reordering providers
  - Renamed `PROVIERS_LIST_2` → `PROVIDERS_LIST_2` and `PROVIERS_LIST_3` → `PROVIDERS_LIST_3`
  - Removed `PROVIERS_LIST_1` and replaced its usage with `Provider.__providers__`
  - Changed `cls.audio_models` initialization from `{}` to `[]`
  - Adjusted handling of model mapping with `clean_name` for consistency
  - GeminiPro check updated to `if provider == GeminiPro`
  - Changed final `cls.audio_models` assignment to `[ *cls.audio_models ]` instead of `list(cls.audio_models.keys())`
  - Adjusted provider fallback in `AnyProvider` to use `PROVIDERS_LIST_2 + PROVIDERS_LIST_3`

- **g4f/requests/__init__.py**:
  - Changed SSE parsing condition from `line.startswith(b"data: ")` to `line.startswith(b"data:")`
  - Updated slice from `line[6:]` to `line[5:]` when extracting `rest
2025-08-18 17:44:05 +02:00
hlohaus
f12649c1d3 Add OpenRouterFree provider 2025-08-10 05:07:55 +02:00
hlohaus
71adc96bce Update model list 2025-08-09 04:44:58 +02:00
hlohaus
f93786fc6c Update model list 2025-08-08 02:45:17 +02:00
hlohaus
9563f8df3a feat: Update environment variables and modify model mappings
- Added `OPENROUTER_API_KEY` and `AZURE_API_KEYS` to `example.env`.
- Updated `AZURE_DEFAULT_MODEL` to "model-router" in `example.env`.
- Added `AZURE_ROUTES` with multiple model URLs in `example.env`.
- Changed the mapping for `"phi-4-multimodal"` in `DeepInfraChat.py` to `"microsoft/Phi-4-multimodal-instruct"`.
- Added `media` parameter to `GptOss.create_completion` method and raised a `ValueError` if `media` is provided.
- Updated `model_aliases` in `any_model_map.py` to include new mappings for various models.
- Removed several model aliases from `PollinationsAI` in `any_model_map.py`.
- Added new models and updated existing models in `model_map` across various files, including `any_model_map.py` and `__init__.py`.
- Refactored `AnyModelProviderMixin` to include `model_aliases` and updated the logic for handling model aliases.
2025-08-07 01:21:22 +02:00
hlohaus
a62a1b6e71 Update models list 2025-08-06 20:54:32 +02:00
hlohaus
d4b46f34de fix: correct typo in API section title and update links, and adjust provider aliases
- Changed "Inference API" to "Interference API" and updated corresponding documentation links in README.md
- Removed "o1" and "dall-e-3" entries from Copilot.py model_aliases
- Added "stream" and "extra_body" parameters with default values in Azure.py's create_async_generator method
- In CopilotAccount.py, included model_aliases with "gpt-4", "gpt-4o", "o1", and "dall-e-3"
- Updated conditional for provider comparison from "==" to "in" list in any_provider.py
- Modified g4f/api/__init__.py to set g4f_api_key from environment variable
- In backend_api.py, added "user" field to cached data with default "unknown"
- Changed logic in OpenaiTemplate.py read_response to check if "choice" exists before processing, and cleaned up indentation and conditionals in response parsing
- Removed unnecessary "stop" and "prompt" parameters from comments or unused code in OpenaiTemplate.py
- Tightened the check for "provider" comparison in any_provider.py to handle multiple providers properly
2025-08-01 00:18:29 +02:00
hlohaus
91b658dbb1 Disable PenguinAI provider
Remove codegeneration.ai api_key
2025-07-21 17:35:55 +02:00
hlohaus
6f8c5ea62b active_by_default 2025-07-15 13:49:29 +02:00
kqlio67
7965487830
feat: add new providers and update models (#3075)
* feat: add agent CLI, new providers, and update models

- Add a new `agent` mode to the CLI, a feature-rich AI coding assistant with capabilities for file system operations, code execution, git integration, and interactive chat.
- Add new provider `OperaAria` with support for vision, streaming, and conversation history.
- Add new provider `Startnest` with support for `gpt-4o-mini`, vision, and streaming.
- Move providers `FreeGpt` and `Websim` to the `not_working` directory.
- Delete the `OIVSCodeSer2` provider.
- Rename the CLI `client` mode to `chat` and refactor its argument parsing.

- In `g4f/Provider/DeepInfraChat.py`:
  - Add a new `api_endpoint` attribute.
    - Extensively update and reorganize the `models` list and `model_aliases` dictionary with numerous new models.

    - In `g4f/Provider/LambdaChat.py`:
      - Change the `default_model` to `deepseek-v3-0324`.

      - In `g4f/Provider/Together.py`:
        - Update aliases for `llama-3.1-405b`, `deepseek-r1`, and `flux`.
          - Add new models including `gemma-3-27b`, `gemma-3n-e4b`, and `qwen-3-32b`.

          - In `g4f/models.py`:
            - Add new model definitions for `aria`, `deepseek_v3_0324_turbo`, `deepseek_r1_0528_turbo`, and several `gemma` variants.
              - Remove the `mixtral_8x22b` model definition.
                - Update the `best_provider` lists for `default`, `default_vision`, `gpt_4o_mini`, `gemini-1.5-pro`, `gemini-1.5-flash`, and others to reflect provider changes.

                - In `g4f/Provider/__init__.py`:
                  - Add `OperaAria` and `Startnest` to the list of imported providers.
                    - Remove `FreeGpt`, `OIVSCodeSer2`, and `Websim` from imports.

                    - In `requirements.txt`:
                      - Add `rich` as a new dependency for the agent CLI.

* feat: add gemma-3-4b alias to DeepInfraChat

In g4f/Provider/DeepInfraChat.py, add the gemma-3-4b alias to the model_aliases dictionary.

The new alias points to the google/gemma-3-4b-it model.

* feat: add OIVSCodeSer2 provider

- Create the new provider file .
- The  provider supports the  model and includes a custom  method to generate a .
- Import and include  in .
- Add  to the  for  in .
- Add  to  in .

* feat: add OIVSCodeSer2 provider

- Create the new provider file .
- The  provider supports the  model and includes a custom  method to generate a .
- Import and include  in .
- Add  to the  for  in .
- Add  to  in .

* refactor: Migrate from duckduckgo-search to ddgs library

*   Replaced the  dependency with the new  library.
*   In , updated imports from  to  and  to .
*   Modified the  function in  to use an  context manager instead of a global instance.
*   Updated the  function to catch the new  exception.
*   In , updated the web search import and installation instructions to use .
*   Removed unnecessary comments and simplified f-string formatting in  and .
*   Added  and  to .
*   Added , , and  to the  extras in .

* test: Update web search tests for ddgs library and cleanup code

*   In `etc/unittest/web_search.py`, updated imports from `duckduckgo_search` to `ddgs` and `DDGSError`.
*   Added an import for `MissingRequirementsError` in `etc/unittest/web_search.py`.
*   Modified exception handling in web search tests to catch both `DDGSError` and `MissingRequirementsError`.
*   Removed temporary modification comments in `g4f/cli/agent/agent.py` and `g4f/tools/web_search.py`.

* fix: remove unstable CLI feature due to critical errors

- Remove the experimental CLI coding assistant feature due to multiple stability issues and critical errors in production environments
- Delete the entire `g4f/cli/agent/` directory and all related functionality
- Remove `rich` dependency from `requirements.txt` as it was only used by the removed feature
- Remove `rich` from the `all` extras in `setup.py`
- Revert CLI mode naming from `chat` back to `client` for consistency
- Clean up argument parsing in CLI to remove references to the removed functionality
- Remove installation instructions and imports related to the unstable feature from documentation

This removal is necessary due to:
- Unpredictable behavior causing data loss risks
- Incompatibility with certain system configurations
- Security concerns with unrestricted file system access
- Excessive resource consumption in production environments

Note: This feature may be reintroduced in the future with a more stable and secure implementation that addresses the current limitations and safety concerns.

---------

Co-authored-by: kqlio67 <kqlio67@users.noreply.github.com>
2025-07-11 03:50:59 +02:00
hlohaus
51b4b8bcb3 feat: add model alias handling and update Cloudflare provider
- Introduced `clean_name` function in `Cloudflare.py` to format model names by removing specific suffixes.
- Updated `model_aliases` in `Cloudflare` class with new model mappings, and cleaned up redundant entries.
- Set `models` in the `Cloudflare` class to use keys from `model_aliases`.
- Adjusted the caching logic in `Cloudflare` to include new headers for requests.
- Added `parent` and `login_url` attributes in `DeepInfraChat` class.
- Updated `PollinationsAI` to clean up model retrieval logic and fixed handling of existing checks.
- Refactored `HarProvider` to inherit models and aliases from `LegacyLMArena`.
- Implemented loading environment variables from `.env` file in `cookies.py`.
- Updated default headers in `defaults.py` for user agent and `sec-ch-ua`.
- Cleaned up various model references in `any_model_map.py` to reflect differences in audio, vision, and other model types.
- Added a more centralized handling for API key management in `run_tools.py` to accommodate new nomenclature.
- Enhanced existing logic to allow for more granular loading and utilization of API keys from environment variables.
2025-07-10 03:28:02 +02:00
hlohaus
664b1ce650 Add any_model_map 2025-06-28 06:22:31 +02:00
hlohaus
4485758781 Improve logging 2025-06-19 13:38:32 +02:00
hlohaus
0b2e38e1bd Improve logging 2025-06-19 13:28:08 +02:00
hlohaus
8ebe05499b Improve logging 2025-06-19 13:15:10 +02:00
hlohaus
a2a1d63836 Improve logging 2025-06-19 12:57:12 +02:00
hlohaus
d824d77d65 feat: Refactor PollinationsAI and ARTA provider structure
- Updated `PollinationsAI.py` to strip trailing periods and newlines from the prompt before encoding.
- Modified the encoding of the prompt to remove trailing percent signs after URL encoding.
- Simplified the audio response handling in `PollinationsAI.py` by removing unnecessary checks and yielding chunks directly.
- Renamed `ARTA.py` to `deprecated/ARTA.py` and updated import paths accordingly in `__init__.py`.
- Changed the `working` status of the `ARTA` class to `False` to indicate it is deprecated.
- Enhanced the `Video` class in `Video.py` to include aspect ratio handling and improved URL response caching.
- Updated the `RequestConfig` class to use a dictionary for storing URLs associated with prompts.
- Removed references to the `ARTA` provider in various files, including `models.py` and `any_provider.py`.
- Adjusted the `best_provider` assignments in `models.py` to exclude `ARTA` and include `HuggingFaceMedia` where applicable.
- Updated the response handling in `Video.py` to yield cached responses when available.
2025-06-19 00:42:41 +02:00
H Lohaus
eb27708f73
Update any_provider.py 2025-06-17 16:59:20 +02:00
hlohaus
b7d1a03dfc Add video provider 2025-06-17 16:30:00 +02:00
hlohaus
c508b79765 Remove unused files 2025-06-16 21:43:02 +02:00
hlohaus
dbef5facb6 Update providers 2025-06-15 11:03:49 +02:00
hlohaus
44040773a5 Catch get_models errors in AnyProvider 2025-06-14 18:11:12 +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
kqlio67
15d8318ab7
feat: Add dev tools, reorganize providers, and expand model support (#3019)
* feat: add repository path support and new md2html converter tool

- Add `--repo` argument to commit.py for specifying git repository path with validation
- Add `validate_git_repository()` function to check repository existence and git status
- Add `get_repository_info()` function to extract branch and remote information
- Update `get_git_diff()` and `make_commit()` functions to accept repository path parameter
- Add Path import and repository validation in main workflow
- Enhance error messages with repository-specific guidance and context
- Update argument parser description and help text for new repository functionality
- Expand module docstring with comprehensive usage examples and feature descriptions
- Add new md2html.py tool for converting Markdown files to HTML using GitHub API
- Add template.html file with GitHub-styled CSS and responsive design
- Implement batch processing, retry logic, and rate limit handling in md2html converter
- Add comprehensive command-line interface with directory processing and custom output options

* refactor: Update provider configurations and model handling

- Removed Dynaspark provider entirely by deleting `g4f/Provider/Dynaspark.py`
- Deprecated DDG provider by moving to `not_working` directory and updating imports
- Restructured HuggingFace and MiniMax providers into `needs_auth` subpackage:
  - Moved all HuggingFace provider files to `needs_auth/hf/`
    - Moved MiniMax providers to `needs_auth/mini_max/`
    - Updated ARTA provider:
      - Expanded `model_aliases` with new tattoo styles and added aliases
        - Added `get_model()` method for model resolution with list support
        - Simplified Blackbox provider:
          - Removed openrouter models and agentMode configurations
            - Reduced model lists to core GPT variants
              - Set session/subscriptionCache to None in payload
              - Added model resolution to Gemini providers:
                - Implemented `get_model()` in Gemini.py and GeminiPro.py
                  - Added alias handling with list support
                  - Updated model definitions in `g4f/models.py`:
                    - Removed references to Dynaspark and DDG providers
                      - Added new SDXL image models with ARTA provider
                        - Adjusted best_provider assignments across multiple models
                        - Removed Dynaspark/DDG references from provider imports and AnyProvider
                        - Added DDG to not_working providers in `__init__.py`

* feat: Add new models to DeepInfraChat, LambdaChat, and models

- Add 'deepseek-ai/DeepSeek-R1-0528' model to DeepInfraChat provider's models list
- Include alias 'deepseek-r1-0528' for DeepSeek-R1-0528 in DeepInfraChat's model_aliases
- Add 'apriel-5b-instruct' model to LambdaChat provider's models list
- Define new 'deepseek-r1-0528' model in models.py with DeepSeek base provider and DeepInfraChat as best provider

* refactor: simplify model registry and add validation

- Remove unused imports: sys, inspect, Set, Type
- Remove ModelRegistry._discovered flag and automatic discovery mechanism
- Add ModelRegistry.clear() method for resetting registry state
- Implement ModelRegistry.list_models_by_provider() for provider-based filtering
- Add ModelRegistry.validate_all_models() for configuration checks
- Remove Model._registered field and simplify registration logic
- Fix gemma_3_12b model name from empty string to 'gemma-3-12b'
- Add image model section header in model definitions
- Replace ModelUtils.convert dict with dynamic property
- Remove ModelUtils.refresh() method
- Register 'gemini' alias directly in ModelRegistry after model creation
- Remove module-level model discovery and ModelUtils.convert initialization

* refactor: Replace ModelUtils.convert property with class variable

- Add class variable `convert` to `ModelUtils` initialized as empty dictionary
- Replace `@property convert` method with `refresh()` class method that updates `convert`
- Remove dynamic property returning `ModelRegistry.all_models()`
- Add module-level assignment to initialize `ModelUtils.convert` with `ModelRegistry.all_models()`
- Include comment for clarity on filling the convert dictionary

* refactor: Reorganize providers and update model configuration

- Removed unused providers from `g4f/Provider/__init__.py`: ChatGpt, Pi, Pizzagpt, PuterJS, You
- Moved LMArenaBeta provider to `needs_auth` directory with updated relative imports
- Moved Pi provider to `needs_auth` directory with updated relative imports
- Moved PuterJS provider to `needs_auth` directory with updated relative imports
- Moved You provider to `needs_auth` directory with updated relative imports
- Added LMArenaBeta, Pi, PuterJS, You to `needs_auth/__init__.py`
- Moved ChatGpt provider to `not_working` directory with updated relative imports
- Moved Pizzagpt provider to `not_working` directory with updated relative imports
- Added ChatGpt, Pizzagpt to `not_working/__init__.py`
- Updated `g4f/models.py` to remove Reka import and change reka_core model provider
- Changed reka_core model's best_provider from IterListProvider to LegacyLMArena in `g4f/models.py`

* feat: add Together provider and update model handling

- Add new provider `Together` in `g4f/Provider/Together.py` with model aliases and configuration
- Implement `get_activation_key` and `get_models` methods in `Together` provider
- Add `get_model` method to resolve aliases in `Together` and `DeepInfraChat`
- Update `DeepInfraChat` model mappings to support multiple versions
  - Change "deepseek-v3" to list with two model options
    - Change "deepseek-r1" to list with two model options
      - Remove duplicate "deepseek-v3" entry
        - Remove "mistral-small" alias
        - Remove "midjourney" from `PollinationsAI.extra_image_models`
        - Register `Together` provider in `g4f/Provider/__init__.py`
        - Update `g4f/models.py` with new providers and models
          - Add `Together` to default and default_vision provider lists
            - Add `Together` as provider for multiple existing models
              - Add new vision model `qwen_2_vl_72b`
                - Add new text models: `qwen_2_5_7b`, `deepseek_r1_distill_qwen_1_5b`, `deepseek_r1_distill_qwen_14b`
                  - Add new image models: `flux_redux`, `flux_depth`, `flux_canny`, `flux_kontext_max`, `flux_dev_lora`, `flux_kontext_pro`
                    - Remove `pi` model definition
                      - Update provider assignments for multiple models to include `Together`

* refactor: Remove LegacyLMArena provider and update model best_providers

- Remove LegacyLMArena import from Provider list in models.py
- Delete LegacyLMArena from default model's best_provider IterListProvider
- Remove multiple obsolete model definitions (gpt_3_5_turbo, gpt_4_turbo, phi_3_small, etc.) that exclusively used LegacyLMArena
- Update best_provider for all remaining models to remove LegacyLMArena from IterListProvider arguments
- Replace LegacyLMArena with alternative providers in model definitions (e.g., OpenaiChat, Together, DeepInfraChat)
- Simplify model definitions by removing redundant IterListProvider wrappers for single providers
- Expand provider imports in any_provider.py to include Blackboxapi, OIVSCodeSer2, etc.
- Extend provider list in AnyProvider with additional working providers for fallback support

* refactor: Remove Blackboxapi provider

- Deleted Blackboxapi provider implementation file
- Removed Blackboxapi import from provider __init__ file
- Updated default model configuration to exclude Blackboxapi provider
- Removed Blackboxapi from llama-3.1-70b model's best_provider
- Updated any_provider to exclude Blackboxapi from provider list

* fix: add missing parameters to Together.get_model method signature

- Add api_key and api_base parameters to get_model method in Together class
- Import random module at the top of the file
- Add inline import comment for random module inside get_model method

* fix: remove broken providers and update model configurations

- Remove non-working providers: ChatGLM, DocsBot, GizAI, OIVSCodeSer5
- Fix Blackbox provider by removing userSelectedModel logic
- Update DeepInfraChat default model to 'deepseek-ai/DeepSeek-V3-0324'
- Add random model selection for DeepInfraChat aliases
- Update LambdaChat default model to 'deepseek-v3-0324' and expand model list
- Fix LegacyLMArena model loading with better error handling and caching
- Add retry logic and timeouts to LegacyLMArena streaming responses
- Improve LegacyLMArena response parsing to handle various data formats
- Update model references across g4f/models.py to remove deleted providers
- Fix AnyProvider model categorization logic for better grouping
- Add LegacyLMArena and ARTA to special provider handling in AnyProvider
- Update provider imports in __init__.py to exclude removed providers
- Add needs_auth flag to You.com and HailuoAI providers
- Fix GeminiPro get_model method signature to accept kwargs

* fix (g4f/Provider/LambdaChat.py)

* refactor: format models list in LMArenaBeta provider

- Convert single-line models array to multi-line format
- Add 11 new models (hunyuan, flux-kontext-pro, cobalt variants, etc.)
- Remove 6 models (bagel, goldmane, redsword, etc.)
- Update stephen model ID

---------

Co-authored-by: kqlio67 <kqlio67.noreply.github.com>
2025-06-11 15:29:27 +02:00
kqlio67
4f2bf3048b refactor: remove deprecated providers, rename LMArenaProvider, update LMArena and models
- Deleted multiple deprecated providers including Acytoo, AiAsk, AiService, Aibn, Aivvm, Berlin, ChatAnywhere, ChatgptDuo, CodeLinkAva, Cromicle, DfeHub, EasyChat, FakeGpt, FastGpt, Forefront, GPTalk, GeekGpt, GetGpt, H2o, Hashnode, Myshell, NoowAi, Opchatgpts, OpenAssistant, V50, Vitalentum, VoiGpt, Wewordle, Wuguokai, Ylokh, Yqcloud, and corresponding deprecated/__init__.py
- Renamed LMArenaProvider.py to LMArena.py and incorporated its functionality with enhancements, including updated model lists, aliases, comprehensive model discovery, payload building, and asynchronous generator for completions
- Removed LMArenaProvider import and added LMArena import in Provider/__init__.py
- Modified Blackbox provider:
  - Removed generate_session_data method and updated generate_session to use fixed email
    - Updated session payload usage in send request to use generate_session without email argument
      - Added asyncMode flag set to False in session payload
      - In DeepInfraChat, removed model aliases for "llama-4-maverick-17b" and "llama-4-scout-17b"
      - In PollinationsAI, updated model aliases: replaced "command-r-plus-08-2024" with "command-r-plus"; added "gpt-image" and "grok-3-mini" aliases
      - In LambdaChat, added "llama-3.3-70b" mapping to "llama3.3-70b-instruct"
      - In hf_space:
        - Deleted Qwen_QVQ_72B and Voodoohop_Flux1Schnell providers
          - Updated model_aliases in Qwen_Qwen_2_5_Max to fix model alias key from "qwen-2-5-max" to "qwen-2.5-max"
            - Changed model_aliases in StabilityAI_SD35Large from "stable-diffusion-3.5-large" to "sd-3.5-large"
              - Removed imports of deleted providers in hf_space/__init__.py and updated defaults accordingly
              - In BingCreateImages moved import to relative from .bing.create_images
              - Moved bing directory into needs_auth directory and updated imports accordingly
              - Changed PuterJS provider:
                - Changed working flag from True to False
                  - Changed return_conversation default from False to True in create_async_generator
                    - Changed yield error messages to raising exceptions for authentication and rate limits
                    - Modified models.py:
                      - Added ModelRegistry class for dynamic registration and lookup of Model instances
                        - Modified Model dataclass to auto-register instances on initialization via ModelRegistry
                          - Adjusted imports and removed PuterJS from lists of providers and best_provider assignments
                            - Replaced many references of PuterJS as best_provider with LMArena or IterListProvider including core models like gpt-3.5-turbo, gpt-4, gpt-4o, llama series, mistral, hermes, Microsoft phi, gemini, anthopic claude, cohere, qwen, deepseek, and others
                              - Fixed aliases and model names (e.g., "qwen-2-5-max" to "qwen-2.5-max")
                                - Removed outdated or deprecated model definitions referencing PuterJS
                                - Updated HarProvider label to "LM Arena (Har)" from "LM Arena"
                                - Removed deprecated providers imports from Provider/__init__.py and not_working directory imports updated accordingly
                                - Various exact functions impacted: create_async_generator in providers Blackbox, LMArena, PollinationsAI, LambdaChat, PuterJS; model aliases and model definitions in models.py; Provider package __init__.py files; BingCreateImages import; and deletions of numerous deprecated providers and not_working providers.
2025-05-25 21:38:12 +03: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
33b3e1d431 Fix unittests 2025-05-16 00:27:27 +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
kqlio67
c3d61ad9e3 refactor: update providers and models for better compatibility
- Changed default model in commit.py from "gpt-4o" to "claude-3.7-sonnet"
- Fixed ARTA provider by adding proper auth token handling and form data submission
- Updated Blackbox provider to use OpenRouter models instead of premium models
- Improved DDG provider with simplified authentication and better error handling
- Updated DeepInfraChat provider with new models and aliases
- Removed non-working providers: Goabror, Jmuz, OIVSCode, AllenAI, ChatGptEs, FreeRouter, Glider
- Moved non-working providers to the not_working directory
- Added BlackboxPro provider in needs_auth directory with premium model support
- Updated Liaobots provider with new models and improved authentication
- Renamed Microsoft_Phi_4 to Microsoft_Phi_4_Multimodal for clarity
- Updated LambdaChat provider with direct API implementation instead of HuggingChat
- Updated models.py with new model definitions and provider mappings
- Removed BlackForestLabs_Flux1Schnell from HuggingSpace providers
- Updated model aliases across multiple providers for better compatibility
- Fixed Dynaspark provider endpoint URL to prevent spam detection
2025-05-12 20:24:36 +03:00
hlohaus
ab5a089b7e feat: add Qwen Qwen-3 provider and update audio/media handling
- Introduce `Qwen_Qwen_3` provider in `g4f/Provider/hf_space/Qwen_Qwen_3.py`
- Register Qwen_Qwen_3 in `g4f/Provider/hf_space/__init__.py` and add it to `HuggingSpace`
- Update `MarkItDown` in `g4f/Provider/audio/MarkItDown.py` to accept and forward `llm_client` and `llm_model` kwargs; add async handling for `text_content`
- Modify audio route in `g4f/api/__init__.py` to pass `llm_client` for MarkItDown and set `modalities` only for other providers
- Adjust `OpenaiChat` (needs_auth) to merge media for upload and check for media presence before requesting images
- Change `get_tempfile` in `g4f/tools/files.py` to determine suffix from file extension using `os.path.splitext`
- Refactor provider listing and model mapping in `AnyProvider.get_models()` (g4f/providers/any_provider.py) to update provider order, support new `HarProvider`, initialize attributes, and guard against model_aliases being None
- Ensure `AnyProvider.create_async_generator` calls `get_models` before working with providers
2025-05-01 10:22:12 +02:00
hlohaus
c3632984f7 feat: add audio speech generation endpoint and media handling refactor
- Added new `/v1/audio/speech` and `/api/{path_provider}/audio/speech` endpoints in `g4f/api/__init__.py` for generating speech from text
- Introduced `AudioSpeechConfig` model in `g4f/api/stubs.py` with fields for input, model, provider, voice, instructions, and response format
- Updated `PollinationsAI.py` to support `modalities` in `kwargs` when checking for audio
- Set default voice for audio models in `PollinationsAI.py` if not provided in `kwargs`
- Added debug print in `PollinationsAI.py` to log request data to text API endpoint
- Extended supported FastAPI response types in `g4f/api/__init__.py` to include `FileResponse` from `starlette.responses`
- Added `BackgroundTask` to clean up generated audio files after serving in `g4f/api/__init__.py`
- Modified `AnyProvider.py` to include `EdgeTTS`, `gTTS`, and `MarkItDown` as audio providers when `audio` is in `kwargs` or `modalities`
- Created `resolve_media` helper in `g4f/client/__init__.py` to standardize media handling for audio/image input
- Replaced manual media preprocessing in `Completions`, `AsyncCompletions`, and `Images` classes with `resolve_media`
- Added `/docs/README.md` with a link to the documentation site
2025-04-26 12:21:49 +02:00
hlohaus
b15a83ae13 feat: add audio transcription endpoint and MarkItDown audio provider integration
- Added new MarkItDown audio provider in g4f/Provider/audio/MarkItDown.py for handling audio transcription using markitdown external module
- Included MarkItDown provider import in g4f/Provider/audio/__init__.py
- Implemented /v1/audio/transcriptions POST API endpoint with support for file upload, model selection, provider choice, and prompt in g4f/api/__init__.py
- Added TranscriptionResponseModel Pydantic schema to g4f/api/stubs.py for transcription responses
- Fixed media tuple handling in g4f/client/__init__.py to correctly unpack and assign file/name pairs in Completions, Images, and AsyncCompletions classes
- Updated g4f/Provider/LambdaChat.py to remove redundant origin attribute and simplify URL assignment
- Added handling in AnyProvider to append provider if model is matched in provider map and provider is working (g4f/providers/any_provider.py)
- Modified backend_api.py to fix web_search logic and default filter_markdown parameter extraction from query parameters
2025-04-26 02:21:30 +02:00
hlohaus
2e928c3b94 ```
docs: update media examples and add parameter details for TTS providers

- Updated EdgeTTS example to mention additional audio parameters (`rate`, `volume`, `pitch`)
- Updated gTTS example to include support for `tld` and `slow` audio parameters
- Modified the EdgeTTS provider to use `get_last_message` instead of `format_image_prompt` for prompt handling
- Modified the gTTS provider to use `get_last_message` instead of `format_image_prompt` for prompt handling
- Refactored audio file generation logic in the gTTS provider to handle `language` parameter and update the voice model accordingly
- Refactored backend API code to introduce `cast_str` function for processing responses, including cache management and response formatting
- Fixed a bug in `AnyProvider` where the model string check would fail if the model was `None`
- Added check in `to_string` helper function to handle `None` values correctly
```
2025-04-20 13:54:46 +02:00
hlohaus
2f46008228 fix: update media file mode and add working check for providers
* In `g4f/client/__init__.py` within the `Images.get_b64_from_url` function, change the file open mode from `"wb"` to `"rb"` to correctly read file data.
* In `g4f/providers/any_provider.py`, add an `if provider.working:` condition before checking if the provider matches the model criteria, ensuring that only working providers are appended.
2025-04-19 04:06:16 +02:00
hlohaus
e83282fc4b feat: add EdgeTTS audio provider and global image→media refactor
- **Docs**
  - `docs/file.md`: update upload instructions to use inline `bucket` content parts instead of `tool_calls/bucket_tool`.
  - `docs/media.md`: add asynchronous audio transcription example, detailed explanation, and notes.

- **New audio provider**
  - Add `g4f/Provider/audio/EdgeTTS.py` implementing Edge Text‑to‑Speech (`EdgeTTS`).
  - Create `g4f/Provider/audio/__init__.py` for provider export.
  - Register provider in `g4f/Provider/__init__.py`.

- **Refactor image → media**
  - Introduce `generated_media/` directory and `get_media_dir()` helper in `g4f/image/copy_images.py`; add `ensure_media_dir()`; keep back‑compat with legacy `generated_images/`.
  - Replace `images_dir` references with `get_media_dir()` across:
    - `g4f/api/__init__.py`
    - `g4f/client/stubs.py`
    - `g4f/gui/server/api.py`
    - `g4f/gui/server/backend_api.py`
    - `g4f/image/copy_images.py`
  - Rename CLI/API config field/flag from `image_provider` to `media_provider` (`g4f/cli.py`, `g4f/api/__init__.py`, `g4f/client/__init__.py`).
  - Extend `g4f/image/__init__.py`
    - add `MEDIA_TYPE_MAP`, `get_extension()`
    - revise `is_allowed_extension()`, `to_input_audio()` to support wider media types.

- **Provider adjustments**
  - `g4f/Provider/ARTA.py`: swap `raise_error()` parameter order.
  - `g4f/Provider/Cloudflare.py`: drop unused `MissingRequirementsError` import; move `get_args_from_nodriver()` inside try; handle `FileNotFoundError`.

- **Core enhancements**
  - `g4f/providers/any_provider.py`: use `default_model` instead of literal `"default"`; broaden model/provider matching; update model list cleanup.
  - `g4f/models.py`: safeguard provider count logic when model name is falsy.
  - `g4f/providers/base_provider.py`: catch `json.JSONDecodeError` when reading auth cache, delete corrupted file.
  - `g4f/providers/response.py`: allow `AudioResponse` to accept extra kwargs.

- **Misc**
  - Remove obsolete `g4f/image.py`.
  - `g4f/Provider/Cloudflare.py`, `g4f/client/types.py`: minor whitespace and import tidy‑ups.
2025-04-19 03:20:57 +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