Commit graph

3279 commits

Author SHA1 Message Date
hlohaus
082c152248 Fix unittests 2025-05-17 11:08:52 +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
hlohaus
8132cf6abc Fix unittests 2025-05-15 02:36:49 +02:00
hlohaus
e2bb1b1f0d fix: update provider implementations and fix SSL handling
- Fix SSL parameter in Liaobots provider (change verify_ssl to ssl=False)
- Simplify model aliases in PollinationsAI by removing list-based random selection
- Add referrer parameter to PollinationsAI provider methods
- Fix image URL generation in PollinationsAI to prevent URL length issues
- Add Gemini-2.5-flash model to Gemini provider models dictionary
- Add Gemini-2.5-pro alias in Gemini provider
- Remove try/except blocks in Provider/__init__.py for more direct imports
- Fix response_format handling in PollinationsAI provider
- Update RequestLogin handling in Gemini provider
2025-05-15 02:21:25 +02:00
kqlio67
13eaf147d3 feat: Update model aliases and add model retrieval method
- Changed the model alias for "gpt-4.1-nano" to be a list containing "openai-fast" and "openai-small".
- Updated the model alias for "gpt-4.1" to be a list containing "openai", "openai-large", and "openai-xlarge".
- Modified the model alias for "gpt-4.1-mini" to be a list containing "openai", "openai-roblox", and "roblox-rp".
- Changed the model alias for "deepseek-r1" to be a list containing "deepseek-reasoning-large" and "deepseek-reasoning".
- Added a new class method `get_model` to retrieve the internal model name based on user-provided model names, including handling for aliases that are lists.
- Implemented error handling in `get_model` to raise a `ModelNotFoundError` if the model is not found.
2025-05-14 12:34:44 +03:00
kqlio67
1ebe48b39f feat: Enhance DDG provider with user agent and hash generation
- Added `hashlib` import to enable hash generation.
- Introduced `generate_user_agent` method to create a dynamic user agent string.
- Modified `generate_fe_version` to accept `page_content` as a parameter and extract the feature hash.
- Added `generate_x_vqd_hash_1` method to compute a hash based on `vqd` and `fe_version`.
- Updated `create_async_generator` to use the new user agent and hash generation methods.
- Simplified message history management by using a single line to find the last user message.
- Removed unnecessary comments and improved code readability.
2025-05-14 12:18:05 +03:00
kqlio67
db88fac742 fix: remove debug print statement from ARTA provider
- Removed a debug print statement that was logging the payload being sent in the ARTA provider
- The removed line was printing form_data with the message "Sending payload: {form_data}"
- This change helps clean up unnecessary logging in the production code
2025-05-12 21:18:23 +03:00
kqlio67
0344571b1f fix: update provider status and fix line ending issues
- Mark FreeRouter provider as not working by changing working=True to working=False
- Fix line ending issues in DuckDuckGo.py and LMArenaProvider.py by ensuring proper newline at end of file
2025-05-12 20:45:53 +03: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
H Lohaus
9fdb60369e
Merge pull request #2978 from hlohaus/26Apr
fix: update error handling, URL, and media name logic across providers
2025-05-06 15:26:22 +02:00
hlohaus
9e8bc2b77f fix: update error handling, URL, and media name logic across providers
- Changed documentation URL in README.md for detailed guidance link
- In g4f/Provider/Cloudflare.py, broadened exception handling in async argument fetching to catch all exceptions in one place and only specific exceptions in another
- In g4f/Provider/PollinationsAI.py, removed raising of exception for unknown model not in image_models and replaced it with pass
- In g4f/Provider/needs_auth/OpenaiChat.py, modified session post call to always use cls._headers
- Changed if-chain in OpenaiChat.py to use elif for checking element prefix "sediment://"
- Added logic to extract and yield generated images for unique "file-service://" matches in streamed responses within OpenaiChat.py
- Commented out multimodal_text image asset pointer handling in OpenaiChat.py
- In g4f/client/__init__.py resolve_media(), set media name to basename of file path using os.path.basename
2025-05-05 22:52:48 +02:00
H Lohaus
79ad4dccb7
Merge pull request #2973 from SreejiBR/main
Update Qwen_Qwen_3.py
2025-05-02 17:12:16 +02:00
Sreejith BR
376c0fdbbf
Update Qwen_Qwen_3.py
This PR addresses an issue where some text type updates from the process_generating stream were not being yielded, resulting in missing output content.

Root Cause
update[2] blocks with type: "text" were not handled unless embedded in certain paths. As a result, standalone or final text entries were silently ignored during streaming.

Solution
Added explicit handling for type: "text" updates.
2025-05-01 22:05:35 +05:30
H Lohaus
1c0eaa9bd4
Merge pull request #2972 from hlohaus/26Apr
feat: add Qwen Qwen-3 provider and update audio/media handling
2025-05-01 10:52:04 +02:00
hlohaus
a3e47f0e74 refactor: update model filtering logic in get_models method
- Modified `get_models` method in `TypeGPT` class in `g4f/Provider/TypeGPT.py`
- Changed model filtering condition to exclude models starting with `-` instead of including only those starting with `+`
- Replaced `model.split("@")[0][1:]` with `model.split("@")[0].strip("+")` to extract model name without leading `+
2025-05-01 10:29:58 +02: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
H Lohaus
9ec553067f
Merge pull request #2964 from hlohaus/26Apr
feat: Improve handling of media and API response structures
2025-04-30 19:32:57 +02:00
hlohaus
c9e1bd21fb refactor: wrap nodriver fallback logic in async function in Cloudflare.py
- Replaced inline `get_args_from_nodriver` logic with a new async function `nodriver_read_models` inside `Cloudflare` class
- Added `async def nodriver_read_models()` to handle asynchronous execution of `get_args_from_nodriver` and call `read_models()`
- Moved `try/except` block for handling `RuntimeError` and `FileNotFoundError` inside the new async function
- Updated fallback assignment `cls.models = cls.fallback_models` and debug logging to be within `nodriver_read_models` exception handler
- Replaced `asyncio.run(args)` with `asyncio.run(nodriver_read_models())` to execute the new async function
- Modified logic inside `except ResponseStatusError` block in `Cloudflare` class to incorporate the new structure
2025-04-30 18:13:36 +02:00
hlohaus
ae3543904f Update README.md 2025-04-30 17:44:27 +02:00
hlohaus
5b72a5d2dc feat: update default params and HTTP 200 response content
- Changed default value of `return_conversation` from `False` to `True` in `Grok._create_completion` method in `g4f/Provider/needs_auth/Grok.py`
- Updated HTTP 200 response mapping to use `{"content": {"audio/*": {}}}` instead of `{"class": FileResponse}` in `Api.markdown_to_audio` method in `g4f/api/__init__.py
2025-04-27 21:52:56 +02:00
hlohaus
da6506707b feat: Improve handling of media and API response structures
- Added validation for `media` parameter in `MarkItDown` class to raise `ValueError` if `media` is not provided.
- Included a check for `has_markitdown` in `MarkItDown` class to raise `ImportError` if `markitdown` is not installed.
- Refactored API response structure by defining `responses` as a reusable dictionary in `g4f/api/__init__.py`.
- Updated `/v1/chat/completions` endpoint to include a new parameter `conversation_id` in the `chat_completions` function.
- Enhanced logic in `chat_completions` to set `conversation_id` from configuration or function input.
- Added a new endpoint `/api/{provider}/{conversation_id}/chat/completions` in `g4f/api/__init__.py` to handle chat completions with `conversation_id`.
- Replaced duplicate response dictionary definitions with the reusable `responses` dictionary in the `/api/{provider}/chat/completions` and `/v1/chat/completions` endpoints.
2025-04-27 01:10:05 +02:00
H Lohaus
1d20051adc
Merge pull request #2963 from hlohaus/26Apr
Update documenation links
2025-04-26 23:54:02 +02:00
hlohaus
528ccd3a74 Update documenation links 2025-04-26 23:53:03 +02:00
hlohaus
affe390c60 Update link documentation 2025-04-26 23:31:10 +02:00
hlohaus
e5a49cdb6d Set return_conversation to True 2025-04-26 23:10:06 +02:00
hlohaus
e238ca3a58 refactor: update model mappings, error handling, and file utils
- Changed `generate_commit_message` return to `.strip("`").strip()` in `commit.py`
- Added new model mappings in `PollinationsAI.py`, including `gpt-4.1`, `gpt-4.1-mini`, and `deepseek-r1-distill-*`
- Removed `print` debug statement from `PollinationsAI.py` request payload
- Replaced temp file handling in `MarkItDown.py` with `get_tempfile` utility
- Added `get_tempfile` function to `files.py` for consistent tempfile creation
- Added `gpt-4.1` to `text_models` list in `models.py`
- Added `ModelNotSupportedError` to exception handling in `OpenaiChat.py`
- Updated message content creation to use `to_string()` in `OpenaiChat.py`
- Wrapped `get_model()` in try-except to ignore `ModelNotSupportedError` in `OpenaiChat.py`
- Adjusted `convert` endpoint in `api/__init__.py` to accept optional `provider` param
- Refactored `/api/markitdown` to reuse `convert()` handler in `api/__init__.py
2025-04-26 17:50:48 +02:00
H Lohaus
dc0705c082
Update models.py 2025-04-26 12:34:25 +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
H Lohaus
7bcf321077
Update README.md 2025-04-25 21:19:05 +02:00
H Lohaus
7464a644e1
Update README.md 2025-04-25 17:07:38 +02:00
H Lohaus
af96e350c8
Update README.md 2025-04-25 11:02:50 +02:00
H Lohaus
511be348cd
Merge pull request #2955 from hlohaus/18Apr
Move documentation
2025-04-25 07:21:22 +02:00
hlohaus
80c835552d Move documentation 2025-04-25 07:13:25 +02:00
H Lohaus
417ffab570
Merge pull request #2952 from hlohaus/18Apr
feat: enhance HAR provider, image handling, markdown upload & cache
2025-04-24 21:39:54 +02:00
hlohaus
5ff7c88428 refactor: simplify websocket message handling and add cache load logic
- Modified `Cloudflare` class in `Cloudflare.py` to add logic for loading `_args` from a cache file if it exists and `_args` is `None`
- Inserted code in `Cloudflare.py` to check existence of cache file and read JSON content into `_args`
- Refactored `Copilot` class in `Copilot.py` by removing `try`/`finally` block around websocket message loop
- Moved websocket close logic to the end of the message handling loop in `Copilot.py`
- Removed nested `try`/`except` block inside the websocket loop in `Copilot.py`
- Preserved original message handling structure while simplifying control flow in `Copilot.py
2025-04-24 19:54:02 +02:00
hlohaus
8243a47f75 fix: Correct handling of kwargs["media"] in Completions and AsyncCompletions
- Updated `kwargs["media"]` assignment in the `Completions` class to use a list containing a tuple instead of a single tuple.
- Removed an unnecessary blank line in the `AsyncCompletions` class after adjusting `kwargs["media"]` values.
- Changes affect the `g4f/client/__init__.py` file, specifically the `Completions` and `AsyncCompletions` classes.
2025-04-24 19:43:06 +02:00
hlohaus
e9c75e99fa fix: update model config and improve version fallback handling
- Changed `DEFAULT_MODEL` from `"o1"` to `"gpt-4o"` in `etc/tool/commit.py`
- Replaced `FALLBACK_MODELS` list with an empty list in `etc/tool/commit.py`
- Moved spinner stop logic inside content-checking block in `generate_commit_message` in `etc/tool/commit.py`
- Trimmed trailing characters "` \n" from returned content in `generate_commit_message` in `etc/tool/commit.py`
- Wrapped cache check in `g4f/gui/server/api.py` in a `try` block to catch `RuntimeError`
- Ensured fallback to `version.utils.latest_version` if cache access fails in `g4f/gui/server/api.py
2025-04-24 19:37:56 +02:00
hlohaus
99b02eed6e feat: Add default model attributes and improve caching logic
- Added `audio_models` attribute in `EdgeTTS.py` to store available audio models.
- Defined `default_model` attribute in `gTTS.py` with `"en-US"` and added `audio_models` list.
- Introduced `default_model` in `HarProvider` within `har/__init__.py` and updated model retrieval logic.
- Modified `HuggingFaceMedia.py` to change the `label` attribute from `"HuggingFace (Image/Video Generation)"` to `"HuggingFace"`.
- Improved caching behavior in `base_provider.py` by ensuring the cache file is written only once per generation cycle.
- Removed redundant `finally` block in `base_provider.py` that was rewriting the cache file unnecessarily.
2025-04-24 19:30:55 +02:00
H Lohaus
cdbcbbd35b
Merge pull request #2917 from theRedCount/main
Add Support for Web Search via SearXNG
2025-04-24 17:16:30 +02:00
hlohaus
ba20b2f302 fix: remove unused tool_calls and debug logging, fix file ops
- Removed default `tool_calls` assignment from `Api.__call__` in `api.py`
- Removed `debug.error()` logging in two exception blocks in `api.py`
- Fixed malformed URL in `CohereForAI_C4AI_Command.url` by removing leading tab in `CohereForAI_C4AI_Command.py`
- Replaced incorrect `result.text_content` access with just `result` in `Backend_Api.upload_bucket` in `backend_api.py`
- Replaced `shutil.copyfile` with `os.rename`, and added fallback to `shutil.copyfile` on failure in `Backend_Api.upload_bucket` in `backend_api.py
2025-04-24 16:44:48 +02:00
hlohaus
8f63f656a2 feat: enhance HAR provider, image handling, markdown upload & cache
- **g4f/Provider/har/__init__.py**
  - `get_models`/`create_async`: iterate over `(domain, harFile)` and filter with `domain in request_url`
  - `read_har_files` now yields `(domain, har_data)`; fixes file variable shadowing and uses `json.load`
  - remove stray `print`, add type hint for `find_str`, replace manual loops with `yield from`
  - small whitespace clean-up

- **g4f/Provider/needs_auth/Grok.py**
  - `ImagePreview` now passes `auth_result.cookies` and `auth_result.headers`

- **g4f/Provider/needs_auth/OpenaiChat.py**
  - add `Union` import; rename/refactor `get_generated_images` → `get_generated_image`
  - support `file-service://` and `sediment://` pointers; choose correct download URL
  - return `ImagePreview` or `ImageResponse` accordingly and stream each image part
  - propagate 422 errors, update prompt assignment and image handling paths

- **g4f/client/__init__.py**
  - drop unused `ignore_working` parameter in sync/async `Completions`
  - normalise `media` argument: accept single tuple, infer filename when missing, fix index loop
  - `Images.create_variation` updated to use the new media logic

- **g4f/gui/server/api.py**
  - expose `latest_version_cached` via `?cache=` query parameter

- **g4f/gui/server/backend_api.py**
  - optional Markdown extraction via `MarkItDown`; save rendered text as `<file>.md`
  - upload flow rewrites: copy to temp file, move to bucket/media dir, clean temp, store filenames
  - introduce `has_markitdown` guard and improved logging/exception handling

- **g4f/tools/files.py**
  - remove trailing spaces in HAR code-block header string

- **g4f/version.py**
  - add `latest_version_cached` `@cached_property` for memoised version lookup
2025-04-24 15:18:21 +02:00
theRedCount
c3625c56b0 Add SearXNG provider and support in web_search 2025-04-23 12:53:08 +02:00
theRedCount
9790c955a9 Add SearXNG provider and support in web_search 2025-04-23 12:53:08 +02:00
H Lohaus
1eb213938d
Merge pull request #2939 from hlohaus/18Apr
18 apr
2025-04-23 02:54:39 +02:00
H Lohaus
beb4adef4f
Merge pull request #2946 from BuT9l3b/test
Refactor: Update Provider import paths in Api module
2025-04-23 02:53:51 +02:00
hlohaus
db47d71f4c Fix generate image in OpenaiChat 2025-04-23 02:53:04 +02:00
hlohaus
9aba62733a Fix generate image in OpenaiChat
Add HarProvider, disable LMArenaProvider
2025-04-23 02:52:43 +02:00