Commit graph

3296 commits

Author SHA1 Message Date
hlohaus
c0d31c2abb refactor: improve media rendering and response formatting with precise changes
- Modified g4f/providers/response.py to ensure format_images_markdown returns the result directly without additional flags in the 'format_images_markdown' function.
- Updated g4f/gui/server/api.py to add 'tempfiles' parameter with default empty list to '_create_response_stream' method.
- Changed or added code in API response handling to iterate over 'tempfiles' and attempt to remove each file after response completion, with exception handling (try-except block with logger.exception).
- Adjusted g4f/Tools/files.py to fix tempfile creation: corrected the 'suffix' parameter in 'get_tempfile' to use 'suffix' directly instead of splitting.
- In g4f/tools/media.py, changed 'render_part' function to handle 'text' key properly, checking 'part.get("text")' and returning a dictionary with 'type': 'text' and 'text': value, if present.
2025-05-19 08:15:21 +02:00
H Lohaus
ff0618e25f
Merge pull request #3002 from hlohaus/kq
feat: integrate Pollinations AI enhancements and simplify gpt4free re…
2025-05-18 05:22:11 +02:00
hlohaus
4aa0bc0745 Update README.md 2025-05-18 05:19:22 +02:00
hlohaus
d937b9b34f test: add custom Reasoning comparison in TestThinkingProcessor
- Added `assertEqualReasoning` method to `TestThinkingProcessor` for comparing `Reasoning` instances
- Replaced `assertEqual` calls with `assertEqualReasoning` in:
  - `test_thinking_chunk`
  - `test_thinking_end`
  - `test_thinking_start_and_end`
  - `test_ongoing_thinking`
  - `test_chunk_with_text_after_think` (except index 0)
- Ensured comparison logic handles both `Reasoning` and non-`Reasoning` cases
2025-05-18 05:10:55 +02:00
hlohaus
362c2f0f1a refactor: improve image response handling, adjust aspect ratio defaults, and fix filename construction
- In PollinationsAI.py, modified get_image method to initialize responses set and manage concurrent image fetches with asyncio tasks, adding a while loop to yield responses as they complete
- Changed response index in get_image from 1 to 0 to align with zero-based indexing
- Introduced 'responses' set and 'finished' counter outside inner get_image function for proper progress tracking
- Updated gather() usage to run all get_image tasks concurrently after loop
- In __init__.py, enhanced use_aspect_ratio function: added checks if width and height are None before assigning aspect ratio-based defaults
- Assigned default width and height values for aspect ratios "1:1", "16:9", and "9:16" if not already specified in extra_body
- In copy_images.py, corrected get_filename function to convert tags to strings before joining with '+', ensuring proper filename formatting
- In response.py, refined is_content function to exclude Reasoning objects where is_thinking and token are both None
- Removed __eq__ method from Reasoning class to prevent comparison issues
- In web_search.py, simplified import by removing unused datetime and date modules
2025-05-18 04:51:46 +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
H Lohaus
af87e97e49
Merge pull request #2998 from hlohaus/kq
Fix pydantic  error
2025-05-17 18:39:40 +02:00
hlohaus
aed21d7f12 Fix unittests 2025-05-17 18:38:03 +02:00
hlohaus
8994c77dcf Fix pydantic error 2025-05-17 17:51:47 +02:00
hlohaus
dfba2954f8 Fix pydantic error 2025-05-17 17:48:08 +02:00
H Lohaus
3449f7e5f5
Merge pull request #2997 from hlohaus/kq
Fix build docker image
2025-05-17 17:38:31 +02:00
hlohaus
ecbf86c2a8 Fix build docker image 2025-05-17 17:38:08 +02:00
hlohaus
c0e323b543 Fix build docker image 2025-05-17 17:35:35 +02:00
H Lohaus
e1b06407ea
Merge pull request #2995 from hlohaus/kq
fix: improve error handling and add type checks in various providers …
2025-05-17 11:20:57 +02:00
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
H Lohaus
654e046092
Update README.md 2025-05-16 14:06:01 +02:00
H Lohaus
7752f1411b
Merge pull request #2990 from hlohaus/kq
fix: resolve model duplication and improve provider handling
2025-05-16 00:29:25 +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
H Lohaus
d2a967c887
Merge pull request #2989 from hlohaus/kq
Update providers and models for better compatibility
2025-05-15 02:52:14 +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