Commit graph

3528 commits

Author SHA1 Message Date
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
426130f3d0 Fix uittests 2025-07-13 13:30:35 +02:00
hlohaus
bd58d3b1d3 Fix uittests 2025-07-13 13:26:55 +02:00
hlohaus
44c7e7735a Fix uittests 2025-07-13 13:16:02 +02:00
hlohaus
120eef46e1 Fix ddgs search 2025-07-13 13:03:39 +02:00
hlohaus
acffc939cf Fix ddgs search 2025-07-13 12:55:59 +02:00
hlohaus
c4b18df769 Support audio model in Azure provider 2025-07-12 19:41:23 +02:00
hlohaus
ebff7d51ab Update README.md 2025-07-12 12:39:42 +02:00
hlohaus
200d830bca Fix typo interference 2025-07-12 12:25:04 +02:00
hlohaus
62803546a6 Fix using nodriver 2025-07-12 11:45:21 +02:00
hlohaus
7f6b528e44 Fix generate video 2025-07-12 09:18:20 +02:00
hlohaus
c50f2f47ff Fix missing cookies in Copilot 2025-07-12 09:08:00 +02:00
hlohaus
dc98d0cb37 Fix unittests 2025-07-12 08:34:42 +02:00
hlohaus
d6ba724bcc Fix unittests 2025-07-12 08:33:42 +02:00
hlohaus
9bee0dd5ba Add note to discord 2025-07-12 08:29:47 +02:00
hlohaus
e48ca345b5 Fix pass api_key 2025-07-12 07:59:47 +02:00
hlohaus
9655954a0b Add custom api_keys 2025-07-12 07:48:48 +02:00
H Lohaus
0327a940cc
Update default_issue.md 2025-07-11 14:09:47 +02:00
hlohaus
78f9e2b0b2 Add example.env 2025-07-11 12:55:15 +02:00
H Lohaus
afe62c308e
Update copilot.py 2025-07-11 09:27:46 +02:00
H Lohaus
56948ae387
Update BlackForestLabs_Flux1KontextDev.py 2025-07-11 09:25:14 +02:00
hlohaus
f8f4a21faf feat: add BlackForestLabs Flux1KontextDev image generation provider
- Added `BlackForestLabs_Flux1KontextDev.py` to `g4f/Provider/hf_space` implementing image generation with streaming via HuggingFace Space
- Registered `BlackForestLabs_Flux1KontextDev` in `g4f/Provider/hf_space/__init__.py`
- Implemented `create_async_generator` to handle media upload, token fetching, and async result streaming
- Defined `run` method to POST and GET requests to the queue endpoint using ZeroGPU headers
- Added logic to process and upload media using `FormData` and `merge_media`
- Introduced `login_url` and `get_models` method in `Azure` provider with use of `AZURE_DEFAULT_MODEL` environment variable in `g4f/Provider/needs_auth/Azure.py
2025-07-11 08:02:03 +02:00
hlohaus
210dfdc537 Add azure provider 2025-07-11 05:57:04 +02:00
kqlio67
7965487830
feat: add new providers and update models (#3075)
* feat: add agent CLI, new providers, and update models

- Add a new `agent` mode to the CLI, a feature-rich AI coding assistant with capabilities for file system operations, code execution, git integration, and interactive chat.
- Add new provider `OperaAria` with support for vision, streaming, and conversation history.
- Add new provider `Startnest` with support for `gpt-4o-mini`, vision, and streaming.
- Move providers `FreeGpt` and `Websim` to the `not_working` directory.
- Delete the `OIVSCodeSer2` provider.
- Rename the CLI `client` mode to `chat` and refactor its argument parsing.

- In `g4f/Provider/DeepInfraChat.py`:
  - Add a new `api_endpoint` attribute.
    - Extensively update and reorganize the `models` list and `model_aliases` dictionary with numerous new models.

    - In `g4f/Provider/LambdaChat.py`:
      - Change the `default_model` to `deepseek-v3-0324`.

      - In `g4f/Provider/Together.py`:
        - Update aliases for `llama-3.1-405b`, `deepseek-r1`, and `flux`.
          - Add new models including `gemma-3-27b`, `gemma-3n-e4b`, and `qwen-3-32b`.

          - In `g4f/models.py`:
            - Add new model definitions for `aria`, `deepseek_v3_0324_turbo`, `deepseek_r1_0528_turbo`, and several `gemma` variants.
              - Remove the `mixtral_8x22b` model definition.
                - Update the `best_provider` lists for `default`, `default_vision`, `gpt_4o_mini`, `gemini-1.5-pro`, `gemini-1.5-flash`, and others to reflect provider changes.

                - In `g4f/Provider/__init__.py`:
                  - Add `OperaAria` and `Startnest` to the list of imported providers.
                    - Remove `FreeGpt`, `OIVSCodeSer2`, and `Websim` from imports.

                    - In `requirements.txt`:
                      - Add `rich` as a new dependency for the agent CLI.

* feat: add gemma-3-4b alias to DeepInfraChat

In g4f/Provider/DeepInfraChat.py, add the gemma-3-4b alias to the model_aliases dictionary.

The new alias points to the google/gemma-3-4b-it model.

* feat: add OIVSCodeSer2 provider

- Create the new provider file .
- The  provider supports the  model and includes a custom  method to generate a .
- Import and include  in .
- Add  to the  for  in .
- Add  to  in .

* feat: add OIVSCodeSer2 provider

- Create the new provider file .
- The  provider supports the  model and includes a custom  method to generate a .
- Import and include  in .
- Add  to the  for  in .
- Add  to  in .

* refactor: Migrate from duckduckgo-search to ddgs library

*   Replaced the  dependency with the new  library.
*   In , updated imports from  to  and  to .
*   Modified the  function in  to use an  context manager instead of a global instance.
*   Updated the  function to catch the new  exception.
*   In , updated the web search import and installation instructions to use .
*   Removed unnecessary comments and simplified f-string formatting in  and .
*   Added  and  to .
*   Added , , and  to the  extras in .

* test: Update web search tests for ddgs library and cleanup code

*   In `etc/unittest/web_search.py`, updated imports from `duckduckgo_search` to `ddgs` and `DDGSError`.
*   Added an import for `MissingRequirementsError` in `etc/unittest/web_search.py`.
*   Modified exception handling in web search tests to catch both `DDGSError` and `MissingRequirementsError`.
*   Removed temporary modification comments in `g4f/cli/agent/agent.py` and `g4f/tools/web_search.py`.

* fix: remove unstable CLI feature due to critical errors

- Remove the experimental CLI coding assistant feature due to multiple stability issues and critical errors in production environments
- Delete the entire `g4f/cli/agent/` directory and all related functionality
- Remove `rich` dependency from `requirements.txt` as it was only used by the removed feature
- Remove `rich` from the `all` extras in `setup.py`
- Revert CLI mode naming from `chat` back to `client` for consistency
- Clean up argument parsing in CLI to remove references to the removed functionality
- Remove installation instructions and imports related to the unstable feature from documentation

This removal is necessary due to:
- Unpredictable behavior causing data loss risks
- Incompatibility with certain system configurations
- Security concerns with unrestricted file system access
- Excessive resource consumption in production environments

Note: This feature may be reintroduced in the future with a more stable and secure implementation that addresses the current limitations and safety concerns.

---------

Co-authored-by: kqlio67 <kqlio67@users.noreply.github.com>
2025-07-11 03:50:59 +02:00
hlohaus
85bd2cbf28 Allow list for PuterJS extra_data 2025-07-11 02:11:01 +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
H Lohaus
48e3577033
Update PollinationsAI.py 2025-07-10 21:43:15 +02:00
H Lohaus
40678de99c
Update Cloudflare.py 2025-07-10 10:10:12 +02:00
hlohaus
6c6b0a6be0 Fix conversation support 2025-07-10 07:35:19 +02:00
hlohaus
031f09b2e6 Fix generate thumbnails 2025-07-10 06:25:07 +02:00
hlohaus
9665da9d61 fix: improve browser handling, prompt encoding, and data merging
- In `Grok.py`, replaced `browser.main_tab` with `await browser.get(cls.url)` to ensure correct page initialization
- Reordered page actions in `Grok.py` by invoking `await page.reload()` after attaching request handler
- In `Video.py`, modified prompt encoding by applying `.encode()[:100].decode("utf-8", "ignore").strip()` to handle non-UTF-8 characters safely
- Replaced single try block for clicking "Create" button with retry loop (up to 60 attempts), including exception handling and fallback browser stop
- In `client.py`, changed model assignment logic to check `self.provider is None` before overwriting existing value
- Updated conversation data merging logic in `client.py` to preserve existing `self.data` using dictionary unpacking instead of overwriting completely
2025-07-10 04:37:04 +02:00
hlohaus
344c50a8e5 Fix photoswipe video 2025-07-10 03:49:59 +02:00
hlohaus
97499b8411 fix: ignore .env file in version control
- Modified `.gitignore` to add `.env` entry at the end of the file
- Prevents accidental inclusion of `.env` file in git tracking
- Ensures `.env` is treated as an ignored file going forward
- Appended change resulted in no newline at end of file after addition
2025-07-10 03:28:49 +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
bdc356c4c2 refactor: replace constants module with config module
- Replaced imports of `STATIC_URL` from `..constants` to `..config` in:
  - `g4f/Provider/PollinationsAI.py`
  - `g4f/Provider/PollinationsImage.py`

- Updated `client.py` to import `CONFIG_DIR` and `COOKIES_DIR` from `g4f.config` instead of defining platform-specific directories.

- Changed the handling of conversation history in `ConversationManager`:
  - Updated `self.history` to retrieve data from `data.get("items", [])` instead of `data.get("history", [])`.

- Modified the `stream_response` function to use `media` instead of `image` for handling media content.

- Updated the `save_content` function to accept `media_content` of type `Optional[MediaResponse]` instead of `content`.

- Adjusted the `run_client_args` function to handle media URLs and files more effectively, appending valid media to a list.

- Removed the `constants.py` file and added a new `config.py` file to centralize configuration settings.

- Updated the `CookiesConfig` class to set `cookies_dir` based on the existence of `CUSTOM_COOKIES_DIR`.

- Adjusted the `render` function in `website.py` to correctly handle file paths and requests for HTML files.

- Updated various references to use the new `config` module instead of the removed `constants` module.
2025-07-09 23:21:03 +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
H Lohaus
571a2ac37b
Merge pull request #3071 from GravityTwoG/fix/openaichat-citations
fix/openaichat citations, images, videos, forecast
2025-07-09 19:37:42 +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
GravityTwoG
8d7a31a32c fix: use ref_index and ref_type to match sources. add image, video, forecast references support 2025-07-04 20:34:55 +07:00
GravityTwoG
2fc26939db fix: check if link title is not empty string 2025-07-04 18:58:26 +07:00
hlohaus
78c0d67d54 refactor: streamline auth handling and CLI structure
- Added `fallback_model = "deepseek"` to `PollinationsAI` class in `PollinationsAI.py`
- Modified `PollinationsAI._agenerate` to safely call `get_model` only if `model` is not None
- Removed unused login loop in `OpenaiChat.synthesize` method in `OpenaiChat.py`
- Replaced full CLI parser and main function implementation in `__main__.py` with import from `.main`
- Added `get_auth_result` method to `AsyncAuthedProvider` in `base_provider.py` for reusable auth retrieval
- Replaced repeated auth loading logic in `create_completion` and `create_streaming_completion` with call to `get_auth_result` in `base_provider.py
2025-07-01 03:10:21 +02:00
H Lohaus
dcbeebd662
Update __init__.py 2025-06-30 10:06:56 +02:00
H Lohaus
05bd5051b1
Update __main__.py 2025-06-30 09:55:15 +02:00
H Lohaus
ba898176bf
Update __init__.py 2025-06-30 09:54:36 +02:00
H Lohaus
33ca1b9b83
Update __init__.py 2025-06-30 09:36:22 +02:00
H Lohaus
ca2695ce45
Create __init__.py 2025-06-30 09:36:13 +02:00
hlohaus
90e30c83ef Support none conversation file 2025-06-30 00:25:02 +02:00
hlohaus
8b2d1afd3e fix: Correct conversation loading and improve file handling
- Modify `ConversationManager.load` to fix conversation loading when `self.provider` is not set.
- Update `ConversationManager.load` to correctly handle `self.provider` and `self.data`.
- Change description in `get_parser` from "GPT CLI client with conversation history" to "G4F CLI client with conversation history".
- Improve error handling in `run_client_args` for file reading.
- Add `UnicodeDecodeError` handling when reading input files as text in `run_client_args`.
- Simplify and correct the construction of `input_text` in `run_client_args`.
2025-06-29 23:58:07 +02:00
hlohaus
5e4b9d9866 fix: improve session handling, message formatting, and content saving
- Added `timeout` parameter support to `LMArenaBeta._create_async_generator` and passed it to `StreamSession`
- Ensured fallback to `default_model` in `LMArenaBeta` if `model` is not provided
- Modified `OpenaiChat._create_completion` to rebuild messages excluding assistant roles if conversation ID exists
- Corrected OpenaiChat `nodriver_auth` to await `browser.get` and replaced page access with reload
- Improved `save_content` in `client.py` with robust content extraction, null checks, and logging for missing content
- Removed premature `input_text.strip()` in `stream_response` and relocated it to `run_client_args`
- Simplified and centralized markdown filtering call in `save_content`
- Replaced raw `print` logging in `__init__.py` with `debug.log` for `nodriver` URL opening message
2025-06-29 21:59:22 +02:00