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

XFEstudio/gpt4free

clean code

127352de
kafm <wdxdesperado@qq.com>
提交于

代码差异

1 个文件 +5 -13
Modified g4f/api/__init__.py +5 -13
@@ -20,11 +20,9 @@ import g4f.debug
20 20 from g4f.client import AsyncClient
21 21 from g4f.typing import Messages
22 22
23 global _g4f_api_key
24
25 def create_app():
23 def create_app(g4f_api_key:str = None):
26 24 app = FastAPI()
27 api = Api(app, g4f_api_key=_g4f_api_key)
25 api = Api(app, g4f_api_key=g4f_api_key)
28 26 api.register_routes()
29 27 api.register_authorization()
30 28 api.register_validation_exception_handler()
@@ -53,7 +51,6 @@ class Api:
53 51 self.app = app
54 52 self.client = AsyncClient()
55 53 self.g4f_api_key = g4f_api_key
56 print(g4f_api_key)
57 54 self.get_g4f_api_key = APIKeyHeader(name="g4f-api-key")
58 55
59 56 def register_authorization(self):
@@ -64,7 +61,6 @@ class Api:
64 61 user_g4f_api_key = await self.get_g4f_api_key(request)
65 62 except HTTPException as e:
66 63 if e.status_code == 403:
67 print(e)
68 64 return JSONResponse(
69 65 status_code=HTTP_401_UNAUTHORIZED,
70 66 content=jsonable_encoder({"detail": "G4F API key required"}),
@@ -184,13 +180,9 @@ def run_api(
184 180 bind: str = None,
185 181 debug: bool = False,
186 182 workers: int = None,
187 g4f_api_key: str = None,
188 use_colors: bool = None
183 use_colors: bool = None,
184 g4f_api_key: str = None
189 185 ) -> None:
190
191 global _g4f_api_key
192 _g4f_api_key = g4f_api_key
193
194 186 print(f'Starting server... [g4f v-{g4f.version.utils.current_version}]' + (" (debug)" if debug else ""))
195 187 if use_colors is None:
196 188 use_colors = debug
@@ -198,4 +190,4 @@ def run_api(
198 190 host, port = bind.split(":")
199 191 if debug:
200 192 g4f.debug.logging = True
201 uvicorn.run("g4f.api:create_app", host=host, port=int(port), workers=workers, use_colors=use_colors, factory=True)
193 uvicorn.run(create_app(g4f_api_key), host=host, port=int(port), workers=workers, use_colors=use_colors)