Commit graph

196 commits

Author SHA1 Message Date
H Lohaus
df3c34cd69
Merge pull request #3131 from xtekky/copilot/fix-3128
Fix WebUI authentication bypass for /chat/ endpoint
2025-08-21 08:52:11 +02:00
hlohaus
526292c4c3 Improce check key 2025-08-19 23:54:22 +02:00
copilot-swe-agent[bot]
d0ce56689c Fix WebUI authentication bypass for /chat/ endpoint
Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com>
2025-08-19 14:08:38 +00:00
hlohaus
571af32062 Fix track usage 2025-08-11 22:44:49 +02:00
hlohaus
ea08a7a57d Add model tags to /api 2025-08-09 10:40:47 +02:00
hlohaus
17d36d5106 Add check fingerprint 2025-08-09 09:52:26 +02:00
hlohaus
ba1f9bb3c3 Log requests 2025-08-08 11:44:58 +02:00
hlohaus
b4c3c30766 Fix auth with api_key 2025-08-07 04:39:10 +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
0b6d8e62a1 Fix python combility 2025-07-19 16:13:44 +02:00
hlohaus
36266ae5b3 Filter audio parameter 2025-07-16 10:42:53 +02:00
hlohaus
9868a88199 Fix audio response in API 2025-07-16 10:27:12 +02:00
hlohaus
c718011cb8 Add YouTube provider 2025-07-14 08:49:12 +02:00
hlohaus
89a45f38b6 Fix cors 2025-07-14 04:55:25 +02:00
hlohaus
0c7006f61e Fix cors 2025-07-14 04:35:19 +02:00
hlohaus
58a9207542 Fix cors 2025-07-14 04:29:07 +02:00
hlohaus
659a780f25 Fix cors 2025-07-14 04:02:51 +02:00
hlohaus
6c52234d83 Fix cors 2025-07-14 03:51:46 +02:00
hlohaus
1e1b7efcb1 Fix cors 2025-07-14 02:50:55 +02:00
hlohaus
85d1379427 Update models list 2025-07-14 02:34:45 +02:00
hlohaus
078a214adc Fix cors 2025-07-14 02:11:48 +02:00
hlohaus
ad3a2c17dd Fix cors 2025-07-14 01:47:57 +02:00
hlohaus
113e788914 Log user name 2025-07-13 22:31:21 +02:00
hlohaus
53657646af Update headers 2025-07-13 22:08:12 +02:00
hlohaus
6106ca95c9 Improve logging 2025-07-13 20:07:39 +02:00
hlohaus
a31cb50d6a Add public gen api 2025-07-13 15:31:09 +02:00
hlohaus
9655954a0b Add custom api_keys 2025-07-12 07:48:48 +02:00
hlohaus
3ce8edce27 Remove timeout 2025-06-21 16:54:44 +02:00
hlohaus
9f941ae71b Support timeout in backend_api 2025-06-19 12:18:53 +02:00
hlohaus
c27f0c995e Support timeout in backend_api 2025-06-19 11:29:54 +02:00
hlohaus
04b59558b4 Update video provider 2025-06-19 10:04:43 +02:00
hlohaus
6120c791a9 fix: Update header fallback for last-modified date in copy_images.py
- In g4f/image/copy_images.py, modified the line that retrieves the "date" header
- Changed from `date = response.headers.get("date")` to `date = response.headers.get("last-modified", response.headers.get("date"))` to fallback to "date" if "last-modified" is missing
- No other files or functions were modified besides this line
2025-06-19 02:23:35 +02:00
hlohaus
b5b48ae75c Fix shutdown 2025-06-19 01:04:26 +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
hlohaus
0d8234bc77 Update Video API 2025-06-17 20:36:44 +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
0cb3057c6e Fix show thumbnail 2025-06-16 08:29:07 +02:00
hlohaus
424d44e6ed Fix broken thumbnails 2025-06-15 15:55:54 +02:00
hlohaus
c6bfddecae Update process generate thumbnails 2025-06-15 12:48:24 +02:00
hlohaus
70a0c9aec7 Add support thumbnail for generated images 2025-06-15 03:21:30 +02:00
hlohaus
963c3a585e refactor: Refactor image generation parameters handling
- Updated the `PollinationsAI` class in `g4f/Provider/PollinationsAI.py`:
  - Changed `aspect_ratio` parameter handling to conditionally use default "1:1" if not specified.
  - Enhanced media handling by introducing `media` parameter in `_generate_image` method.
  - Updated parameter processing in `_generate_image_async` method for `model == "gptimage"`.

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

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

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

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

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

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

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

- Updated `BaseRetryProvider` class in `g4f/providers/types.py`:
  - Enhanced handling of `model` and `api_key` parameters in provider iteration.
2025-06-12 14:23:04 +02:00
hlohaus
2befef988b feat: refactor provider create functions to class attributes and update calls
- Added `create_function` and `async_create_function` class attributes with default implementations in `base_provider.py` for `AbstractProvider`, `AsyncProvider`, and `AsyncGeneratorProvider`
- Updated `get_create_function` and `get_async_create_function` methods to return these class attributes
- Replaced calls to `provider.get_create_function()` and `provider.get_async_create_function()` with direct attribute access `provider.create_function` and `provider.async_create_function` across `g4f/__init__.py`, `g4f/client/__init__.py`, `g4f/providers/retry_provider.py`, and `g4f/tools/run_tools.py`
- Removed redundant `get_create_function` and `get_async_create_function` methods from `providers/base_provider.py` and `providers/types.py`
- Ensured all provider response calls now use the class attributes for creating completions asynchronously and synchronously as needed
2025-06-12 12:45:55 +02:00
hlohaus
5734a06193 feat: Enhance PollinationsAI with new models and media handling
- Updated `PollinationsAI.py` to import `quote` and `ClientTimeout` from `aiohttp`.
- Added `MissingAuthError` to error imports in `PollinationsAI.py`.
- Included `AudioResponse` in response imports in `PollinationsAI.py`.
- Expanded `image_models` in `PollinationsAI` to include "turbo" and "gptimage".
- Changed the initialization of `image_models` to use `cls.image_models.copy()`.
- Introduced `download_media` parameter in the `_generate_image` method.
- Added a condition to set `n = 1` if the model is "gptimage".
- Renamed `get_image_url` to `get_url_with_seed` and modified its logic to return the URL for "gptimage".
- Updated the session creation in `_generate_image` to include a timeout.
- Enhanced error handling in the image fetching logic to yield `Reasoning` status.
- Modified the media handling in `save_response_media` to yield `AudioResponse` based on `download_media`.
- Updated `OpenAIFM.py` to include `quote` and `AudioResponse` imports.
- Added `styles` to the `OpenAIFM` class and created a method to group models.
- Introduced `download_media` parameter in the `synthesize` method of `OpenAIFM`.
- Updated the `create_app` function in `api/__init__.py` to check for `a2wsgi` availability.
- Removed unused file handling routes in `api/__init__.py`.
- Updated `secure_filename` function in `files.py` to handle encoding more robustly.
- Added `download_media` to the `RequestConfig` model in `stubs.py`.
2025-06-12 08:37:42 +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
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
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