Commit Graph

99 Commits

Author SHA1 Message Date
hlohaus
f83c92446e fix: update provider status, models, error handling, and imports
- Set `working = False` in Free2GPT, Startnest, and Reka providers
- Changed `default_model` in LambdaChat from `deepseek-v3-0324` to `deepseek-r1`
- Removed `deepseek-v3` alias from LambdaChat's `model_aliases`
- In Kimi provider:
  - Replaced manual status check with `await raise_for_status(response)`
  - Set `model` field to `"k2"` in chat completion request
  - Removed unused `pass` statement
- In WeWordle provider:
  - Removed `**kwargs` from `data_payload` construction
- In Reka provider:
  - Set default value for `stream` to `True`
  - Modified `get_cookies` call to use `cache_result=False`
- In `cli/client.py`:
  - Added conditional import for `MarkItDown` with `has_markitdown` flag
  - Raised `MissingRequirementsError` if `MarkItDown` is not installed
- In `gui/server/backend_api.py`:
  - Imported `MissingAuthError`
  - Wrapped `get_provider_models` call in try-except block to return 401 if `MissingAuthError` is raised
2025-07-27 18:03:54 +02:00
hlohaus
6c52234d83 Fix cors 2025-07-14 03:51:46 +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
3c66fa114a feat: add 'transparent' image model and refactor HAR provider auth flow
- Added "transparent" to `image_models` in `PollinationsAI` and mapped it to "gptimage"
- Modified transparent flag handling in `_generate_image` call in `PollinationsAI`
- Removed unused `cls.get_models()` call from image generation method in `PollinationsAI`
- Replaced `AsyncGeneratorProvider` with `AsyncAuthedProvider` in `HarProvider`
- Implemented `on_auth_async` in `HarProvider` to support browser-based auth via `nodriver`
- Replaced `create_async_generator` with `create_authed` in `HarProvider` to support `AuthResult`
- Removed custom `headers` in HAR post requests; used `auth_result.get_dict()` for `StreamSession`
- Refactored `Video` provider to support optional search in `get_response`
- Added `search` parameter to `RequestConfig.get_response` and `Video.create_async_generator`
- Improved browser automation and element interaction logic in `Video` provider
- Extracted video request interception to collect URLs using `nodriver`
- Reduced video polling loop timeout from 600 to 300 iterations in `Video`
- Updated CLI `client.py` to fix handling of `conversation.conversation` assignment
- Fixed argparse config: removed `nargs='?'` and added `metavar` for `--conversation-file`
- Improved image metadata extraction in API and backend when Pillow is available
- Modified `ImageResponse.__str__` to output HTML anchor/image tags with dimensions if present
- Added support for returning `target_path` from `copy_media` if `return_target` is True
- Changed default image processing size in `process_image` from 800x400 to 400x400
- Disabled RGBA-to-RGB flattening in `process_image`
- Improved `get_args_from_nodriver` to ensure proper referer and cookie handling
- Added helper `get_target_paths_and_urls` in `Api` to extract image dimensions from disk paths
2025-07-11 01:46:32 +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
634f7d9a39 Update validation 2025-06-28 17:04:41 +02:00
hlohaus
a30908ae0b Fix stop_browser, update secret validation 2025-06-27 14:10:30 +02:00
hlohaus
7b5ecaa4fb Add secret validation 2025-06-25 21:30:58 +02:00
hlohaus
c466d414c9 Add ip 2025-06-25 13:42:37 +02:00
hlohaus
6948ab9b7d Fix upload docx 2025-06-24 23:11:21 +02:00
hlohaus
744dfeb957 Add ip ban 2025-06-24 22:25:42 +02:00
hlohaus
85aaa84932 Add model aliases to OpenaiChat 2025-06-20 22:08:56 +02:00
hlohaus
c37f5c0912 Improve update script 2025-06-19 15:54:01 +02:00
hlohaus
ce539f755d Secure api 2025-06-19 14:22:58 +02:00
hlohaus
a0babdc3eb Secure api 2025-06-19 14:20:03 +02:00
hlohaus
2c59301013 Secure api 2025-06-19 14:08:41 +02:00
hlohaus
a323981e72 Serve broken images 2025-06-19 13:47:20 +02:00
hlohaus
0b2e38e1bd Improve logging 2025-06-19 13:28:08 +02:00
hlohaus
a2a1d63836 Improve logging 2025-06-19 12:57:12 +02:00
hlohaus
c27f0c995e Support timeout in backend_api 2025-06-19 11:29:54 +02:00
hlohaus
90262b1f6a Fix copy image 2025-06-19 10:40:36 +02:00
hlohaus
04b59558b4 Update video provider 2025-06-19 10:04:43 +02:00
hlohaus
aa92c2225e Fix missing import 2025-06-19 06:29:26 +02:00
hlohaus
4337fa7fa8 Add user log 2025-06-19 06:19:54 +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
4631083693 Add video provider 2025-06-17 16:42:32 +02:00
hlohaus
b7d1a03dfc Add video provider 2025-06-17 16:30:00 +02:00
hlohaus
4bd1b8652c Fix copy images 2025-06-17 08:30:08 +02:00
hlohaus
c6bfddecae Update process generate thumbnails 2025-06-15 12:48:24 +02:00
hlohaus
ec631789e3 Support thumbnails 2025-06-15 00:56:53 +02:00
hlohaus
aea736d41e Add thumbnail support 2025-06-15 00:42:48 +02:00
hlohaus
74b3137107 Fix load share conversation 2025-06-15 00:06:16 +02:00
hlohaus
28810e4773 Add support image links in UI 2025-06-14 21:38:47 +02:00
hlohaus
c6fead0313 feat: Add LMArenaBeta provider and update existing providers
- Introduced a new provider class `LMArenaBeta` in `g4f/Provider/LMArenaBeta.py` with capabilities for text and image models.
- Updated `g4f/Provider/Cloudflare.py` to remove an unused import of `Cookies`.
- Modified `g4f/Provider/PollinationsAI.py` to change the condition for checking the action in the `next` command.
- Added a new provider `PuterJS` in `g4f/Provider/PuterJS.py` with various model handling and authentication logic.
- Removed the old `PuterJS` implementation from `g4f/Provider/not_working/PuterJS.py`.
- Updated `g4f/Provider/__init__.py` to include the new `LMArenaBeta` and `PuterJS` providers.
- Changed the label of `HarProvider` in `g4f/Provider/har/__init__.py` to "LMArena (Har)".
- Adjusted the model list in `g4f/Provider/openai/models.py` to ensure consistency in model definitions.
- Updated the API response handling in `g4f/providers/response.py` to calculate total tokens in the `Usage` class constructor.
2025-05-29 03:42:17 +02:00
hlohaus
c3aca8964c refactor: adjust model check, tool calls, and response handling logic
- Updated `thinking_enabled` condition in `DeepSeekAPI.py` to ensure `model` is not None before checking substring
- Removed default `tool_calls` value in `/backend-api/v2/create` route in `backend_api.py`
- Simplified response caching logic by consolidating `cast_str` handling and ensuring `response` is a string before writing
- Adjusted response filtering logic to handle string vs iterable cases more consistently
- Refined safe search tag check in file matching loop to only test the first tag against MIME type in `backend_api.py`
- Changed default filename from "index" to "home" in `_index` method of `website.py
2025-05-21 15:05:43 +02:00
hlohaus
9461949542 feat: improve media handling, file conversion, and error management
- Added UUID-based "x-xai-request-id" header and 403 error handling in Grok.py
- Updated backend_api.py to handle empty media results and unsupported file types with error raising and file cleanup
- Simplified render logic in website.py by removing is_live flag and related code
- Changed "audio/wav" MIME type to "audio/x-wav" in image/__init__.py
- Added is_valid_media and is_valid_audio functions to image/__init__.py for stricter media validation
- Enhanced MarkItDown integration in markitdown/__init__.py with convert_stream method supporting non-seekable streams
- Modified _transcribe_audio.py to use recognize_faster_whisper if available, fallback to recognize_google
- Updated providers/helper.py to prioritize "text" key in to_string function
- Improved stream_read_files in files.py to skip DOWNLOADS_FILE and adjust code block formatting
- Added get_filename_from_url utility in files.py for consistent filename generation from URLs
- Enhanced download_urls in files.py to use MarkItDown for URL conversion and improved error logging
- Improved render_part and related functions in media.py to use new media validation logic and handle more cases
- Adjusted merge_media and render_messages in media.py for stricter part filtering and validation
2025-05-20 22:40:12 +02:00
hlohaus
73f751ef36 fix: handle RuntimeError during asyncio.run in Cloudflare.py and rename key in PollinationsAI.py
- Added try-except block to catch RuntimeError around asyncio.run(nodriver_read_models()) in Cloudflare.py to set cls.models to fallback_models if encountered
- Corrected indentation of "followups" key in PollinationsAI.py from 43 to 44, changing it from nested to proper dictionary key
- No other code logic changed in these files
2025-05-19 11:39:45 +02:00
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
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
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
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
hlohaus
9aba62733a Fix generate image in OpenaiChat
Add HarProvider, disable LMArenaProvider
2025-04-23 02:52:43 +02:00
hlohaus
8c3764dfeb feat: enhance audio model handling and improve image URL resolution
- Updated `PollinationsAI` to exclude "gemini" model from `audio_models`
- Added logic in `PollinationsAI` to expand `audio_models` with voices from `default_audio_model`
- Appended voice names to `text_models` list in `PollinationsAI` if present in `default_audio_model`
- Modified `PollinationsAI._generate_text` to inject `audio` parameters when a voice model is used
- Updated `save_response_media` call to include voice name in model list
- Changed `OpenaiChat.get_generated_image` to support both `file-service://` and `sediment://` URLs using `conversation_id`
- Modified `OpenaiChat.create_messages` to optionally pass `prompt`
- Adjusted `OpenaiChat.run` to determine `prompt` explicitly and set messages accordingly
- Updated `OpenaiChat.iter_messages_line` to handle `None` in `fields.p` safely
- Passed `prompt` and `conversation_id` to `OpenaiChat.get_generated_image` inside image parsing loop
- Fixed redirect logic in `backend_api.py` to safely handle missing `skip` query param
- Enhanced `render` function in `website.py` to support live file serving with `live` query param
- Added new route `/dist/<path:name>` to serve static files from `DIST_DIR` in `website.py`
- Adjusted `render` to include `.live` suffix in cache filename when applicable
- Modified HTML replacements in `render` to preserve local `dist/` path if `add_origion` is True
2025-04-21 08:43:32 +02:00
hlohaus
02384a616a Add set set_browser_executable_path 2025-04-20 22:16:01 +02:00
hlohaus
236d2aa114 Remove client files from main package 2025-04-20 20:44:10 +02:00