yym68686 commited on
Commit
ee53a1b
·
1 Parent(s): 9addb23

📖 Docs: Update documentation

Browse files
Files changed (3) hide show
  1. README.md +0 -16
  2. README_CN.md +0 -16
  3. main.py +17 -0
README.md CHANGED
@@ -172,22 +172,6 @@ yym68686/uni-api:latest
172
  - TIMEOUT: Request timeout, default is 100 seconds. The timeout can control the time needed to switch to the next channel when one channel does not respond. Optional
173
  - DISABLE_DATABASE: Whether to disable the database, default is false, optional
174
 
175
- ## Get statistical data
176
-
177
- Use `/stats` to get the usage statistics of each channel for the past 24 hours. Also include your uni-api admin API key.
178
-
179
- Data includes:
180
-
181
- 1. The success rate of each model under each channel, sorted from high to low.
182
- 2. The overall success rate of each channel, sorted from high to low.
183
- 3. The total number of requests for each model across all channels.
184
- 4. The number of requests for each endpoint.
185
- 5. The number of requests per IP.
186
-
187
- The `hours` parameter in `/stats?hours=48` allows you to control how many hours of recent data statistics to return. If the `hours` parameter is not provided, it defaults to statistics for the last 24 hours.
188
-
189
- There are other statistical data that you can query yourself by writing SQL in the database. Other data includes: first token time, total processing time for each request, whether each request was successful, whether each request passed content moderation, the text content of each request, the API key for each request, the number of input tokens, and the number of output tokens for each request.
190
-
191
  ## Vercel remote deployment
192
 
193
  [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fyym68686%2Funi-api%2Ftree%2Fmain&env=CONFIG_URL,DISABLE_DATABASE&project-name=uni-api-vercel&repository-name=uni-api-vercel)
 
172
  - TIMEOUT: Request timeout, default is 100 seconds. The timeout can control the time needed to switch to the next channel when one channel does not respond. Optional
173
  - DISABLE_DATABASE: Whether to disable the database, default is false, optional
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  ## Vercel remote deployment
176
 
177
  [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fyym68686%2Funi-api%2Ftree%2Fmain&env=CONFIG_URL,DISABLE_DATABASE&project-name=uni-api-vercel&repository-name=uni-api-vercel)
README_CN.md CHANGED
@@ -172,22 +172,6 @@ yym68686/uni-api:latest
172
  - TIMEOUT: 请求超时时间,默认为 100 秒,超时时间可以控制当一个渠道没有响应时,切换下一个渠道需要的时间。选填
173
  - DISABLE_DATABASE: 是否禁用数据库,默认为 false,选填
174
 
175
- ## 获取统计数据
176
-
177
- 使用 `/stats` 获取最近 24 小时各个渠道的使用情况统计。同时带上 自己的 uni-api 的 admin API key。
178
-
179
- 数据包括:
180
-
181
- 1. 每个渠道下面每个模型的成功率,成功率从高到低排序。
182
- 2. 每个渠道总的成功率,成功率从高到低排序。
183
- 3. 每个模型在所有渠道总的请求次数。
184
- 4. 每个端点的请求次数。
185
- 5. 每个ip请求的次数。
186
-
187
- `/stats?hours=48` 参数 `hours` 可以控制返回最近多少小时的数据统计,不传 `hours` 这个参数,默认统计最近 24 小时的统计数据。
188
-
189
- 还有其他统计数据,可以自己写sql在数据库自己查。其他数据包括:首字时间,每个请求的总处理时间,每次请求是否成功,每次请求是否符合道德审查,每次请求的文本内容,每次请求的 API key,每次请求的输入 token,输出 token 数量。
190
-
191
  ## Vercel 部署
192
 
193
  [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fyym68686%2Funi-api%2Ftree%2Fmain&env=CONFIG_URL,DISABLE_DATABASE&project-name=uni-api-vercel&repository-name=uni-api-vercel)
 
172
  - TIMEOUT: 请求超时时间,默认为 100 秒,超时时间可以控制当一个渠道没有响应时,切换下一个渠道需要的时间。选填
173
  - DISABLE_DATABASE: 是否禁用数据库,默认为 false,选填
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  ## Vercel 部署
176
 
177
  [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fyym68686%2Funi-api%2Ftree%2Fmain&env=CONFIG_URL,DISABLE_DATABASE&project-name=uni-api-vercel&repository-name=uni-api-vercel)
main.py CHANGED
@@ -969,6 +969,23 @@ async def get_stats(
969
  token: str = Depends(verify_admin_api_key),
970
  hours: int = Query(default=24, ge=1, le=720, description="Number of hours to look back for stats (1-720)")
971
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
972
  if DISABLE_DATABASE:
973
  return JSONResponse(content={"stats": {}})
974
  async with async_session() as session:
 
969
  token: str = Depends(verify_admin_api_key),
970
  hours: int = Query(default=24, ge=1, le=720, description="Number of hours to look back for stats (1-720)")
971
  ):
972
+ '''
973
+ ## 获取统计数据
974
+
975
+ 使用 `/v1/stats` 获取最近 24 小时各个渠道的使用情况统计。同时带上 自己的 uni-api 的 admin API key。
976
+
977
+ 数据包括:
978
+
979
+ 1. 每个渠道下面每个模型的成功率,成功率从高到低排序。
980
+ 2. 每个渠道总的成功率,成功率从高到低排序。
981
+ 3. 每个模型在所有渠道总的请求次数。
982
+ 4. 每个端点的请求次数。
983
+ 5. 每个ip请求的次数。
984
+
985
+ `/v1/stats?hours=48` 参数 `hours` 可以控制返回最近多少小时的数据统计,不传 `hours` 这个参数,默认统计最近 24 小时的统计数据。
986
+
987
+ 还有其他统计数据,可以自己写sql在数据库自己查。其他数据包括:首字时间,每个请求的总处理时间,每次请求是否成功,每次请求是否符合道德审查,每次请求的文本内容,每次请求的 API key,每次请求的输入 token,输出 token 数量。
988
+ '''
989
  if DISABLE_DATABASE:
990
  return JSONResponse(content={"stats": {}})
991
  async with async_session() as session: