Commit graph

9 commits

Author SHA1 Message Date
hlohaus
89a3da5800 Update STATIC_URL 2025-09-12 09:30:53 +02:00
hlohaus
4c1da4e610 Fix handling of stream_timeout 2025-09-08 05:21:44 +02:00
hlohaus
130a429500 Update download URL in website.py to use GITHUB_URL for improved version handling 2025-09-07 02:27:29 +02:00
hlohaus
2dfa807cfb Refactor provider type determination to use 'chat' for non-image models and update download URL configuration 2025-09-04 12:07:42 +02:00
hlohaus
7c5ec5325a Update EasyChat and OpenRouter classes, modify backend API timing, and enhance website rendering 2025-09-04 02:42:04 +02:00
hlohaus
b6f51f00d8 refactor: restructure core utilities, typing, and request handling
- In `g4f/__init__.py`, changed logger setup to use fixed "g4f" name and refactored `ChatCompletion.create` and `create_async` to share `_prepare_request` logic for preprocessing arguments
- In `g4f/config.py`, added `__future__.annotations`, `lru_cache` import, wrapped `get_config_dir` with `@lru_cache`, and simplified platform branch logic
- In `g4f/cookies.py`, added typing imports, renamed `browsers` to `BROWSERS`, reformatted `DOMAINS`, updated docstrings, improved loop logic in `load_cookies_from_browsers` with additional exception handling, split HAR/JSON parsing into `_parse_har_file` and `_parse_json_cookie_file`, and enhanced `read_cookie_files` with optional filters and `.env` loading
- In `g4f/debug.py`, added enable/disable logging functions, updated log handler typing, appended messages to `logs` in `log()`, and improved `error()` formatting
- In `g4f/errors.py`, introduced base `G4FError` and updated all exception classes to inherit from it or relevant subclasses, with descriptive docstrings for each
- In `g4f/files.py`, added `max_length` parameter to `secure_filename`, adjusted regex formatting, and added docstring; updated `get_bucket_dir` to sanitize parts inline with docstring
- In `g4f/typing.py`, added `__future__.annotations`, reorganized imports, restricted PIL import to type-checking, defined `ContentPart` and `Message` TypedDicts, updated type aliases and `__all__` to include new types
- In `g4f/version.py`, added `lru_cache` and request timeout constant, applied caching to `get_pypi_version` and `get_github_version`, added response validation and explicit exceptions, refactored `VersionUtils.current_version` with clearer sources and error on miss, changed `check_version` to return a boolean with optional silent mode, and improved error handling outputs
2025-08-09 03:29:44 +02:00
hlohaus
a62a1b6e71 Update models list 2025-08-06 20:54: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
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