yym68686 commited on
Commit
2a7fbb2
·
1 Parent(s): 894ff24

Fix the bug that does not adapt to the new API for obtaining the model list.

Browse files
Files changed (2) hide show
  1. README.md +7 -0
  2. main.py +4 -10
README.md CHANGED
@@ -94,6 +94,11 @@ api_keys:
94
  AUTO_RETRY: true # 是否自动重试,自动重试下一个提供商,true 为自动重试,false 为不自动重试,默认为 true
95
  ```
96
 
 
 
 
 
 
97
  ## Docker Local Deployment
98
 
99
  Start the container
@@ -119,6 +124,8 @@ services:
119
  - ./api.yaml:/home/api.yaml
120
  ```
121
 
 
 
122
  Run Docker Compose container in the background
123
 
124
  ```bash
 
94
  AUTO_RETRY: true # 是否自动重试,自动重试下一个提供商,true 为自动重试,false 为不自动重试,默认为 true
95
  ```
96
 
97
+ ## 环境变量
98
+
99
+ - CONFIG_URL: 配置文件的下载地址,可以是本地文件,也可以是远程文件,选填
100
+ - TIMEOUT: 请求超时时间,默认为 20 秒,超时时间可以控制当一个渠道没有响应时,切换下一个渠道需要的时间。选填
101
+
102
  ## Docker Local Deployment
103
 
104
  Start the container
 
124
  - ./api.yaml:/home/api.yaml
125
  ```
126
 
127
+ CONFIG_URL 就是可以自动下载远程的配置文件。比如你在某个平台不方便修改配置文件,可以把配置文件传到某个托管服务,可以提供直链给 uni-api 下载,CONFIG_URL 就是这个直链。
128
+
129
  Run Docker Compose container in the background
130
 
131
  ```bash
main.py CHANGED
@@ -20,7 +20,9 @@ from urllib.parse import urlparse
20
  @asynccontextmanager
21
  async def lifespan(app: FastAPI):
22
  # 启动时的代码
23
- timeout = httpx.Timeout(connect=15.0, read=20.0, write=30.0, pool=30.0)
 
 
24
  default_headers = {
25
  "User-Agent": "curl/7.68.0", # 模拟 curl 的 User-Agent
26
  "Accept": "*/*", # curl 的默认 Accept 头
@@ -239,7 +241,7 @@ async def request_model(request: Union[RequestModel, ImageGenerationRequest], to
239
  async def options_handler():
240
  return JSONResponse(status_code=200, content={"detail": "OPTIONS allowed"})
241
 
242
- @app.post("/v1/models")
243
  async def list_models(token: str = Depends(verify_api_key)):
244
  models = post_all_models(token, app.state.config, app.state.api_list)
245
  return JSONResponse(content={
@@ -247,14 +249,6 @@ async def list_models(token: str = Depends(verify_api_key)):
247
  "data": models
248
  })
249
 
250
- @app.get("/v1/models")
251
- async def list_models():
252
- models = get_all_models(config=app.state.config)
253
- return JSONResponse(content={
254
- "object": "list",
255
- "data": models
256
- })
257
-
258
  @app.post("/v1/images/generations")
259
  async def images_generations(
260
  request: ImageGenerationRequest,
 
20
  @asynccontextmanager
21
  async def lifespan(app: FastAPI):
22
  # 启动时的代码
23
+ import os
24
+ TIMEOUT = os.getenv("TIMEOUT", 20)
25
+ timeout = httpx.Timeout(connect=15.0, read=TIMEOUT, write=30.0, pool=30.0)
26
  default_headers = {
27
  "User-Agent": "curl/7.68.0", # 模拟 curl 的 User-Agent
28
  "Accept": "*/*", # curl 的默认 Accept 头
 
241
  async def options_handler():
242
  return JSONResponse(status_code=200, content={"detail": "OPTIONS allowed"})
243
 
244
+ @app.get("/v1/models")
245
  async def list_models(token: str = Depends(verify_api_key)):
246
  models = post_all_models(token, app.state.config, app.state.api_list)
247
  return JSONResponse(content={
 
249
  "data": models
250
  })
251
 
 
 
 
 
 
 
 
 
252
  @app.post("/v1/images/generations")
253
  async def images_generations(
254
  request: ImageGenerationRequest,