XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Fix server bugs

69fa21ce
hlohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

4 个文件 +11 -7
Modified g4f/Provider/template/OpenaiTemplate.py +5 -2
@@ -10,7 +10,7 @@ from ...image import use_aspect_ratio
10 10 from ...image.copy_images import save_response_media
11 11 from ...providers.response import *
12 12 from ...tools.media import render_messages
13 from ...config import AppConfig
13 from ...config import SPACE_URL, AppConfig
14 14 from ...errors import MissingAuthError
15 15 from ... import debug
16 16
@@ -93,10 +93,13 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
93 93 base_url = cls.backup_url
94 94 if base_url is None:
95 95 raise NotImplementedError("No base_url or backup_url specified.")
96 if base_url.startswith("https://g4f.space/") and not api_key:
96 if base_url.startswith(SPACE_URL) and not api_key:
97 97 api_key = AppConfig.g4f_space_api_key
98 98 elif cls.models_needs_auth and not api_key:
99 99 raise MissingAuthError("API key is required.")
100 elif not base_url.startswith(SPACE_URL) and api_key and (api_key.startswith("g4f_") or api_key.startswith("gfs_")):
101 raise ValueError("Invalid API key for the specified base_url.")
102
100 103 response = requests.get(f"{base_url}/models", headers=cls.get_headers(False, api_key), verify=cls.ssl, timeout=timeout)
101 104 response.raise_for_status()
102 105 data = response.json()
Modified g4f/api/__init__.py +1 -1
@@ -530,7 +530,7 @@ class Api:
530 530 debug.log(f"Invalid user name (screaming): '{user}'")
531 531 return ErrorResponse.from_message("Invalid user name (screaming)", HTTP_401_UNAUTHORIZED)
532 532 debug.log(f"User: '{user}' G4F API key expires in {hours}h {minutes}m {seconds}s")
533 else:
533 elif user is None:
534 534 user = "admin"
535 535 path = request.url.path
536 536 if _requires_api_key(path, AppConfig.demo):
Modified g4f/config.py +1 -0
@@ -33,6 +33,7 @@ GITHUB_REPOSITORY = f"xtekky/{ORGANIZATION}"
33 33 STATIC_DOMAIN = f"{PACKAGE_NAME}.dev"
34 34 STATIC_URL = f"https://{STATIC_DOMAIN}/"
35 35 REFFERER_URL = f"https://{STATIC_DOMAIN}/"
36 SPACE_URL = f"https://g4f.space/"
36 37 DIST_DIR = f"./{STATIC_DOMAIN}/dist"
37 38 DEFAULT_MODEL = "openai/gpt-oss-120b"
38 39 JSDELIVR_URL = "https://cdn.jsdelivr.net/"
Modified g4f/tools/optimize_request.py +4 -4
@@ -1403,10 +1403,10 @@ def optimize_request(messages: Messages, tools: Any) -> Tuple[int, Dict[str, str
1403 1403 logs["dedup"] = f"removed duplicate/empty messages (-{dedup_saved} bytes)"
1404 1404
1405 1405 # ── Break tool-call loops ──
1406 loop_saved = break_tool_loop(messages)
1407 if loop_saved:
1408 saved_bytes += loop_saved
1409 logs["tool_loop"] = f"broke tool-call loop (-{loop_saved} bytes)"
1406 # loop_saved = break_tool_loop(messages)
1407 # if loop_saved:
1408 # saved_bytes += loop_saved
1409 # logs["tool_loop"] = f"broke tool-call loop (-{loop_saved} bytes)"
1410 1410
1411 1411 echo_saved = strip_reasoning_echo(messages)
1412 1412 if echo_saved: