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

XFEstudio/gpt4free

Fix sending api_key

486f8fe0
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

3 个文件 +9 -1
Modified g4f/Provider/DeepInfra.py +1 -0
@@ -212,6 +212,7 @@ class DeepInfra(OpenaiTemplate):
212 212 cls, model, messages, api_key=None, headers=None, **kwargs
213 213 ):
214 214 if not api_key or not cls.is_provider_api_key(api_key):
215 api_key = None # Ensure no API key is sent for web-page requests
215 216 # Generate a Turnstile token for each request (required without an API key)
216 217 token = await get_turnstile_token_async(model)
217 218 if token:
Modified g4f/api/__init__.py +2 -1
@@ -563,7 +563,8 @@ class Api:
563 563 user = None
564 564 if (
565 565 request.method != "OPTIONS"
566 and AppConfig.g4f_api_key is not None ):
566 and AppConfig.g4f_api_key is not None
567 ):
567 568 try:
568 569 user_g4f_api_key = await self.get_g4f_api_key(request)
569 570 except HTTPException:
Modified g4f/gui/server/backend_api.py +6 -0
@@ -356,6 +356,12 @@ class Backend_Api(Api):
356 356 json_data["user"] = request.headers.get("x-user", "error")
357 357 json_data["referer"] = request.headers.get("referer", "")
358 358 json_data["user-agent"] = request.headers.get("user-agent", "")
359 if "api_key" not in json_data:
360 json_data["api_key"] = request.headers.get("authorization")
361 if json_data["api_key"] and json_data["api_key"].startswith(
362 "Bearer "
363 ):
364 json_data["api_key"] = json_data["api_key"][7:]
359 365
360 366 kwargs = self._prepare_conversation_kwargs(json_data)
361 367 try: