Commit graph

25 commits

Author SHA1 Message Date
hlohaus
7c5ec5325a Update EasyChat and OpenRouter classes, modify backend API timing, and enhance website rendering 2025-09-04 02:42:04 +02:00
hlohaus
aab5c045a2 Update api module 2025-08-22 00:09:45 +02:00
hlohaus
05f0f55711 refactor: update providers list, env vars, and minor fixes
- **example.env**:
  - Added `G4F_API_KEY` and `G4F_PROXY` variables
  - Removed Azure-related API keys and routes block
  - Added `OLLAMA_API_KEY`, `NVIDIA_API_KEY`, and `PUTER_API_KEY`

- **g4f/Provider/EasyChat.py**:
  - Replaced `page.js_dumps` with `page.evaluate` for retrieving `guestId`

- **g4f/Provider/deprecated/LegacyLMArena.py**:
  - Changed `working = True` to `working = False`

- **g4f/Provider/deprecated/har/__init__.py**:
  - Changed `working = True` to `working = False`

- **g4f/providers/any_provider.py**:
  - Updated imports, adding `Custom`, `PollinationsImage`, `OpenaiAccount`, and reordering providers
  - Renamed `PROVIERS_LIST_2` → `PROVIDERS_LIST_2` and `PROVIERS_LIST_3` → `PROVIDERS_LIST_3`
  - Removed `PROVIERS_LIST_1` and replaced its usage with `Provider.__providers__`
  - Changed `cls.audio_models` initialization from `{}` to `[]`
  - Adjusted handling of model mapping with `clean_name` for consistency
  - GeminiPro check updated to `if provider == GeminiPro`
  - Changed final `cls.audio_models` assignment to `[ *cls.audio_models ]` instead of `list(cls.audio_models.keys())`
  - Adjusted provider fallback in `AnyProvider` to use `PROVIDERS_LIST_2 + PROVIDERS_LIST_3`

- **g4f/requests/__init__.py**:
  - Changed SSE parsing condition from `line.startswith(b"data: ")` to `line.startswith(b"data:")`
  - Updated slice from `line[6:]` to `line[5:]` when extracting `rest
2025-08-18 17:44:05 +02:00
hlohaus
3a83806903 Disable leagcy lmarena 2025-08-17 15:32: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
422c3dd5ca Only streaming in EasyChat 2025-08-11 01:26:10 +02:00
hlohaus
933b2e15d1 refactor: move DuckDuckGo/Free2GPT to deprecated; SearXNG updates
- g4f/Provider/ApiAirforce.py: replace class attr parent="Api.Airforce" with label="Api.Airforce"
- g4f/Provider/EasyChat.py: add guard after loop to raise ValueError("Failed to retrieve arguments for EasyChat.") when args is falsy
- g4f/Provider/SearXNG.py:
  - add imports: from .helper import format_media_prompt; from .. import debug
  - rename class attr default_url to url (SEARXNG_URL) and use cls.url in requests
  - create(): add parameters prompt: str = None and language: str = "it"
  - build prompt via format_media_prompt(messages, prompt); remove previous query extraction
  - request params: set q to prompt and language to provided language
  - pass proxy to session.get(...); replace print(...) with debug.log(...)
  - on empty results, return early (remove "Nessun risultato trovato." and FinishReason("stop") yields)
  - result formatting: use r.get("title") without default fallback
- g4f/Provider/__init__.py: import DuckDuckGo and Free2GPT from .deprecated.DuckDuckGo and .deprecated.Free2GPT
- g4f/Provider/deprecated/DuckDuckGo.py: update relative imports to ...typing, ..base_provider, ..helper
- g4f/Provider/deprecated/Free2GPT.py: update relative imports to ...errors, ...requests, ...typing, ..base_provider
- g4f/Provider/needs_auth/DeepSeekAPI.py: set working = False (was has_dsk)
- g4f/Provider/needs_auth/You.py: set working = False (was True); update headers["Referer"] to f"{cls.url}/api/streamingSearch"
2025-08-11 00:42:18 +02:00
hlohaus
f12649c1d3 Add OpenRouterFree provider 2025-08-10 05:07:55 +02:00
hlohaus
9defe08a41 Add raise_for_status in share auth 2025-08-10 01:33:39 +02:00
hlohaus
c69b6af69a Add share auth for EasyChat 2025-08-10 01:10:49 +02:00
hlohaus
17d36d5106 Add check fingerprint 2025-08-09 09:52:26 +02:00
hlohaus
f3923f8e50 feat: add new GPT-5 support and improve captcha handling
- **g4f/Provider/Copilot.py**
  - Added `"Smart (GPT-5)"` to `models` list.
  - Added `"gpt-5"` alias mapping to `"GPT-5"` in `model_aliases`.
  - Introduced `mode` selection logic to support `"smart"` mode for GPT-5 models alongside existing `"reasoning"` and `"chat"` modes.
- **g4f/Provider/EasyChat.py**
  - Added `get_models` class method to map `-free` models to aliases and store them in `cls.models`.
  - Resolved model via `cls.get_model(model)` at start of `create_async_generator`.
  - Reset `cls.captchaToken` to `None` at the beginning of `callback`.
  - Wrapped main generator logic in a loop to allow retry once if `CLEAR-CAPTCHA-TOKEN` error occurs, clearing auth file and resetting args.
- **g4f/Provider/needs_auth/OpenaiChat.py**
  - Added handling for image models: detect and set `image_model` flag, use `default_model` when sending requests if image model selected, and include `"picture_v2"` in `system_hints` when applicable.
  - Replaced textarea/button detection code in page load sequence with `nodriver` `select` calls, sending "Hello" before clicking send button, and included profile button selection if class needs auth.
- **g4f/Provider/openai/models.py**
  - Changed `default_image_model` from `"dall-e-3"` to `"gpt-image"`.
  - Added `"gpt-5"` and `"gpt-5-thinking"` to `text_models` list.
  - Added alias mapping for `"dall-e-3"` pointing to new `default_image_model`.
2025-08-09 01:33:56 +02:00
hlohaus
c019c2c4b6 Fix model names 2025-08-08 04:01:56 +02:00
hlohaus
5b65101a2a feat: add delays and input actions for captcha and auth flows
- Added `await asyncio.sleep(1)` inside captcha verification loop in `EasyChat.py` to introduce delay between checks
- Modified `Grok.py` to send "Hello" input to a selected textarea element during auth flow
- Added delay after sending keys to textarea in `Grok.py` using `await asyncio.sleep(1)`
- Added logic to select and click a submit button if present in `Grok.py` during header check loop
- All changes are within the `EasyChat` and `Grok` class definitions respectively
2025-08-08 01:46:15 +02:00
hlohaus
4164cb5978 Move on_request function 2025-08-08 01:37:10 +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
Heiner Lohaus
6a61cf8116 Sort providers in new dirs 2023-10-04 07:20:51 +02:00
Tekky
78bfbe717d
Revert "Fix type hint" 2023-09-17 22:23:54 +01:00
MIDORIBIN
c6f2277906 fix typo: provider -> Provider 2023-09-16 10:36:47 +09:00
Heiner Lohaus
618addd001 Disable not working providers:
EasyChat, Equing, GetGpt, Liaobots and Wuguokai
No and random best provider for a model
Update providers in Readme
2023-09-12 04:40:10 +02:00
msi-JunXiang
901595b10f type hints
Use `from __future__ import annotations avoid `dict` and `list` cause "TypeErro: 'type' object is not subscriptable".

Refer to the following Stack Overflow discussions for more information:
1.
https://stackoverflow.com/questions/75202610/typeerror-type-object-is-not-subscriptable-python
2.
https://stackoverflow.com/questions/59101121/type-hint-for-a-dict-gives-typeerror-type-object-is-not-subscriptable
2023-09-03 16:26:26 +08:00
abc
efd75a11b8 ~ | code styling 2023-08-27 17:37:44 +02:00
Bagus Indrayana
e56f9b7c0d remove whitspace from data: and raise exception 2023-08-24 18:13:20 +08:00
Bagus Indrayana
0dd20ff78d update header & response easychat 2023-08-20 21:38:33 +08:00
MIDORIBIN
f6ef3cb223 refactor: refactor provider 2023-08-14 11:46:32 +09:00