Commit graph

59 commits

Author SHA1 Message Date
hlohaus
af56ac0c03 Enhance MCP server tests to reflect updated tool count; improve model fetching with timeout handling in providers 2025-11-02 08:01:20 +01:00
hlohaus
7ee118e20c Refactor OpenaiTemplate and Api classes for improved error handling and user identification 2025-10-31 06:01:58 +01:00
hlohaus
a18ceac0a5 Add StringableInference provider and update OpenaiTemplate for model retrieval 2025-10-04 12:33:53 +02:00
hlohaus
edfc0e7c79 Enhance Copilot provider with cookie handling and user identity support; add Kimi provider; refactor usage tracking in run_tools. 2025-10-02 18:11:11 +02:00
H Lohaus
c5670047b6
Update OpenaiTemplate.py 2025-10-02 08:20:23 +02:00
hlohaus
f6309cb693 Refactor OpenaiTemplate to remove API key print statement; update model providers by removing Blackbox references; enhance error handling in raise_for_status_async to handle JSON decoding errors gracefully. 2025-10-02 03:12:36 +02:00
hlohaus
7d184411e2 Refactor OIVSCodeSer2 and OIVSCodeSer0501 classes; consolidate Perplexity provider and update OpenaiTemplate for API key handling 2025-10-02 00:55:01 +02:00
hlohaus
9931e874ee Add Perplexity provider and enhance response handling in existing providers 2025-10-01 23:41:38 +02:00
hlohaus
391e1f463e Enhance Azure provider error handling and update environment variables 2025-09-22 22:21:03 +02:00
hlohaus
d7375d4c6c Add Claude provider with authentication handling and update Nvidia provider 2025-09-11 20:55:31 +02:00
hlohaus
217c1e85db Enhance OpenaiTemplate and Nvidia providers with support for text/plain responses and improved error handling 2025-09-09 21:18:47 +02:00
hlohaus
de688319ae Add error handling for missing authentication and Unicode encoding in response streaming 2025-09-08 15:40:32 +02:00
hlohaus
b4ed1a55da Add more live info 2025-09-06 12:42:51 +02:00
hlohaus
5bfea4611a Track live model instances in PollinationsAI, LMArena, OpenaiTemplate, and base_provider classes 2025-09-06 11:48:21 +02:00
hlohaus
1cbf9dfb6a Track live provider instances and update count on success or failure in various providers 2025-09-06 11:28:09 +02:00
hlohaus
e1e34eccb3 Enhance Cohere and OpenRouter providers with API key handling and model management improvements 2025-09-05 18:17:48 +02:00
hlohaus
4132b0a494 feat: add image size support and update nodriver args handling
- **ApiAirforce.py**: Added `use_image_size = True` class attribute.
- **EasyChat.py**: Added `user_data_dir=None` argument when calling `get_args_from_nodriver`.
- **LMArenaBeta.py**:
  - Only set `cls.share_url` from `G4F_SHARE_URL` if `cls.share_url` is `None`.
  - Added `user_data_dir=None` argument when calling `get_args_from_nodriver`.
  - Modified media filtering to check `url` is a `str` before `startswith("https://")`.
- **OpenaiTemplate.py**:
  - Added `use_image_size = False` class attribute.
  - Modified image generation payload to optionally include `"size"` key when `use_image_size` is `True` and width/height present.
  - Refactored `read_response` to store `content` in a variable, strip on first chunk, and yield `ToolCalls` directly from `tool_calls` variable.
- **g4f/requests/__init__.py**:
  - Added `user_data_dir` parameter (default `"nodriver"`) to `get_args_from_nodriver`.
  - Passed `user_data_dir` to `get_nodriver` call.
2025-08-11 15:48:16 +02:00
hlohaus
05148d2b30 Add ApiAirforce provider 2025-08-10 22:28:11 +02:00
hlohaus
a0a7a54b11 Remove print 2025-08-09 18:33:23 +02:00
hlohaus
28c4c61fdd refactor: simplify model alias management and update providers
- Removed specific model aliases for various models (e.g., "gpt-4.1-mini", "phi-4", "grok-3-mini").
- Replaced the `get_model` method with a simplified approach using `get_alias` for alias resolution.
- Updated model alias management in `PollinationsAI` to handle model aliases in `get_models` method.
- Refined the logic for adding models to `text_models` and `vision_models` in `PollinationsAI`.
- Replaced `deepseek-v3` and other model aliases with direct models in `PollinationsAI`.
- Modified `Ollama` class to handle local models and improve model fetching with API key.
- Changed the `create_async_generator` in `Ollama` to support local model handling and proxy use.
- Updated `Azure` class to remove unused `extra_body` argument and streamline stream handling.
- Updated model providers in `g4f/models.py` to remove certain providers (e.g., `PollinationsAI`) from `best_provider` lists for some models.
2025-08-09 17:22:47 +02:00
hlohaus
b6dd7b39be Fix add user in Nvidia 2025-08-09 01:51:44 +02:00
hlohaus
c019c2c4b6 Fix model names 2025-08-08 04:01:56 +02:00
hlohaus
b9dfe1a460 feat: add EasyChat and GLM providers, update HuggingFace and SSE parsing
- Added new `EasyChat` provider (`g4f/Provider/EasyChat.py`) with captcha handling, nodriver callback, and token caching
- Added new `GLM` provider (`g4f/Provider/GLM.py`) with model retrieval, auth token fetch, and SSE streaming support
- Updated `g4f/Provider/__init__.py` to import `EasyChat` and `GLM`
- Modified `LMArenaBeta` in `g4f/Provider/needs_auth/LMArenaBeta.py` to remove nodriver availability check and always use `get_args_from_nodriver` with callback
- Updated `HuggingFaceAPI` in `g4f/Provider/needs_auth/hf/HuggingFaceAPI.py` to use `default_model` from `models` instead of `default_llama_model` and removed commented `max_inputs_lenght` param
- Updated `HuggingFace` in `g4f/Provider/needs_auth/hf/__init__.py` to import `default_model` instead of `default_vision_model`, set `default_model` class attribute, and commented out HuggingFaceInference and image model handling logic
- Modified `OpenaiTemplate` in `g4f/Provider/template/OpenaiTemplate.py` to prefer `"name"` over `"id"` when populating `vision_models`, `models`, and `models_count`
- Enhanced `sse_stream` in `g4f/requests/__init__.py` to strip and skip empty `data:` lines, handle JSON decode errors, and raise `ValueError` on invalid JSON
2025-08-08 01:19:32 +02:00
hlohaus
f8f8251cee Add model count for FenayAI 2025-08-07 06:34:59 +02:00
hlohaus
b3c1d1f3b1 Check api_key for models 2025-08-07 03:02:50 +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
bf285b5665 feat: add GptOss provider and reasoning handling in OpenaiTemplate
- Added new provider `GptOss` in `g4f/Provider/GptOss.py` with support for async message generation via SSE
- Registered `GptOss` in `g4f/Provider/__init__.py`
- Implemented logic in `GptOss.create_async_generator` to handle both new and existing conversations with SSE streaming response handling
- Handled event types including `thread.created`, `thread.item_updated`, and `thread.updated` within `GptOss`
- Modified `read_response` in `OpenaiTemplate.py` to yield `Reasoning` objects using `reasoning_content` or fallback to `reasoning` from `choice["delta"]
2025-08-06 01:52:21 +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
499dcc0154 refactor: replace see_stream with sse_stream and update md2html output logic
- Replaced all imports and usages of `see_stream` with `sse_stream` across:
  - `g4f/Provider/Kimi.py`
  - `g4f/Provider/hf_space/BlackForestLabs_Flux1KontextDev.py`
  - `g4f/Provider/needs_auth/PuterJS.py`
  - `g4f/Provider/template/OpenaiTemplate.py`
  - `g4f/requests/__init__.py` (renamed function `see_stream` to `sse_stream`)
- Modified `g4f/Provider/needs_auth/GeminiPro.py`:
  - Updated `default_model` from `gemini-2.5-flash-preview-04-17` to `gemini-2.5-flash`
  - Removed `gemini-2.5-flash-preview-04-17` from `fallback_models`
- Updated `etc/tool/md2html.py`:
  - Added `re` import
  - Changed `process_single_file_with_output` to check if output file exists
  - If exists, uses regex to update `<title>` and `itemprop="text">` content instead of writing full template
  - If not, generates HTML using the template as before
2025-07-29 19:57:13 +02:00
hlohaus
9868a88199 Fix audio response in API 2025-07-16 10:27:12 +02:00
hlohaus
ffa05f5c4d Fix streaming 2025-07-15 16:02:01 +02:00
hlohaus
b597d84a50 Update YouTube provider 2025-07-15 08:46:08 +02:00
hlohaus
85d1379427 Update models list 2025-07-14 02:34:45 +02:00
hlohaus
c4b18df769 Support audio model in Azure provider 2025-07-12 19:41:23 +02:00
hlohaus
210dfdc537 Add azure provider 2025-07-11 05:57:04 +02:00
hlohaus
dc9f1156ec refactor: streamline image param handling and fix media URL extraction
- Removed extension of `vision_models` into `text_models` in `PollinationsAI.get_models`
- Unified image parameter handling in `PollinationsAI.create_payload`, removing special case for `"gptimage"` model
- Added conditional inclusion of `"transparent"` and `"image"` params based on `transparent` flag and media content
- Replaced `quote_plus` with `quote` for URL encoding in query string construction
- In `OpenaiTemplate.create_payload`, wrapped media URL extraction in `iter()` to fix `next()` usage with list comprehension
2025-07-09 20:25:27 +02:00
hlohaus
6c126e468c feat: update providers, model selection, media handling, and routing
- Added GithubCopilotAPI provider to g4f/Provider/needs_auth and __init__.py
- Fixed typo "GGOGLE_SID_COOKIE" to "GOOGLE_SID_COOKIE" in Gemini.py and updated all references
- Updated PollinationsAI.py:
  - Refined model aliases and removed/commented unused/legacy aliases
  - Updated logic for loading audio and vision models, using swap_models for alias reversals
  - Adjusted get_model and model loading methods for accuracy
  - Changed default model lists for text, image, and vision models
  - Updated conversation title and followup labels for followups tools
- Modified save_content in g4f/cli/client.py to handle url downloads for lists, allow cookies/headers, and removed duplicate HTTP download logic
- Added asyncio sleep after stdout writes in stream_response for smoother streaming
- Changed website.py render default to "home," adjusted chat route to accept any filename, and updated filenames used for rendering
- Updated model selection in g4f/models.py by removing PollinationsAI from best_provider and changing model provider order for specific models
- Enhanced media merging in g4f/tools/media.py to clarify comment about last user message and handle content appending for lists in render_messages
- Updated OpenaiTemplate.py to add an image_url field if media with http(s) URLs is present
- Adjusted test_provider_has_model in etc/unittest/models.py to skip providers requiring auth
2025-07-09 19:36:58 +02:00
hlohaus
989d3b8602 fix: remove redundant lookup for "audio" voice in PollinationsAI.py and fix key reference in OpenaiTemplate.py
- Removed the line retrieving "voice" from "audio" key inside the PollinationsAI.py file
- Changed the condition in OpenaiTemplate.py from checking "choices" in data to "choices" in data before accessing data["choices"][0] in OpenaiTemplate.py
2025-06-19 02:12:44 +02:00
hlohaus
2c3fa23ff0 Update providers 2025-06-15 07:39:37 +02:00
hlohaus
4915048953 Update providers 2025-06-14 14:34:51 +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
f96ea67f50 fix: replace format_image_prompt with format_media_prompt across multiple files
- Updated imports to use format_media_prompt in g4f/Provider/ARTA.py, PollinationsAI.py, PollinationsImage.py, Websim.py, audio/OpenAIFM.py, hf_space/BlackForestLabs_Flux1Dev.py, hf_space/DeepseekAI_JanusPro7b.py, hf_space/G4F.py, hf_space/Microsoft_Phi_4_Multimodal.py, hf_space/StabilityAI_SD35Large.py, needs_auth/BingCreateImages.py, needs_auth/BlackboxPro.py, needs_auth/DeepInfra.py, needs_auth/Gemini.py, needs_auth/MicrosoftDesigner.py, needs_auth/OpenaiChat.py, needs_auth/hf/HuggingChat.py, needs_auth/hf/HuggingFaceInference.py, needs_auth/hf/HuggingFaceMedia.py, not_working/AllenAI.py, template/OpenaiTemplate.py, api.py, and gui/server/api.py
- Replaced calls to format_image_prompt with format_media_prompt in relevant locations
- Changed media prompt handling in various providers to ensure consistent usage of format_media_prompt
- Modified the __aenter__ and __aexit__ methods of requests/aiohttp.py to properly manage ClientSession lifecycle
2025-06-12 03:01:24 +02:00
hlohaus
bf4ed09ab9 feat: Refactor extra_body handling and update model error handling
- Changed the default value of `extra_body` from an empty dictionary to `None` in `ImageLabs` and `PollinationsAI` classes.
- Added a check to initialize `extra_body` to an empty dictionary if it is `None` in the `ImageLabs` class.
- Removed the `extra_image_models` list from the `PollinationsAI` class.
- Updated the way image models are combined in the `PollinationsAI` class to avoid duplicates.
- Changed the error handling for unsupported models from `ModelNotSupportedError` to `ModelNotFoundError` in multiple classes including `OpenaiChat`, `HuggingFaceAPI`, and `HuggingFaceInference`.
- Updated the `save_response_media` function to handle both string and bytes responses.
- Adjusted the handling of audio data in the `PollinationsAI` class to ensure proper processing of audio responses.
2025-06-12 02:29:41 +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
46d0b87008 Add example for video generation
Add support for images in messages
2025-03-27 09:38:31 +01:00
hlohaus
ce500f0d49 Set default model in HuggingFaceMedia
Improve handling of shared chats
Show api_key input if required
2025-03-26 01:32:05 +01:00
hlohaus
8f6efd5366 Update docs: Using the OpenAI Library
Add sse function to requests sessions
Small improvments in OpenaiChat and ARTA provider
2025-03-22 07:32:30 +01:00
hlohaus
fa2344b031 Update openai example in docs, add default api_key 2025-03-21 06:22:38 +01:00
hlohaus
c97ba0c88e Add audio transcribing example and support
Add Grok Chat provider
Rename images parameter to media
Update demo homepage
2025-03-21 03:17:45 +01:00