Skip to content

Commit

Permalink
✨ Feature: Add support for OpenAI JSON format output.
Browse files Browse the repository at this point in the history
📖 Docs: Update documentation
  • Loading branch information
yym68686 committed Oct 6, 2024
1 parent d4d650a commit 599e110
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ api_keys:
- CONFIG_URL: The download address of the configuration file, it can be a local file or a remote file, optional
- TIMEOUT: Request timeout, default is 100 seconds, the timeout can control the time needed to switch to the next channel when a channel does not respond. Optional

## Retrieve Statistical Data

Use `/stats` to get usage statistics for each channel over the last 24 hours. Include your own uni-api admin API key.

The data includes:

1. Success rate for each model under each channel, sorted from highest to lowest success rate.
2. Overall success rate for each channel, sorted from highest to lowest.
3. Total number of requests for each model across all channels.
4. Number of requests for each endpoint.
5. Number of requests from each IP address.

`/stats?hours=48` The `hours` parameter can control how many hours of recent data statistics are returned. If the `hours` parameter is not provided, it defaults to statistics for the last 24 hours.

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 ethical review, text content of each request, API key for each request, input token count, and output token count for each request.

## Docker Local Deployment

Start the container
Expand Down
16 changes: 16 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ api_keys:
- CONFIG_URL: 配置文件的下载地址,可以是本地文件,也可以是远程文件,选填
- TIMEOUT: 请求超时时间,默认为 100 秒,超时时间可以控制当一个渠道没有响应时,切换下一个渠道需要的时间。选填

## 获取统计数据

使用 `/stats` 获取最近 24 小时各个渠道的使用情况统计。同时带上 自己的 uni-api 的 admin API key。

数据包括:

1. 每个渠道下面每个模型的成功率,成功率从高到低排序。
2. 每个渠道总的成功率,成功率从高到低排序。
3. 每个模型在所有渠道总的请求次数。
4. 每个端点的请求次数。
5. 每个ip请求的次数。

`/stats?hours=48` 参数 `hours` 可以控制返回最近多少小时的数据统计,不传 `hours` 这个参数,默认统计最近 24 小时的统计数据。

还有其他统计数据,可以自己写sql在数据库自己查。其他数据包括:首字时间,每个请求的总处理时间,每次请求是否成功,每次请求是否符合道德审查,每次请求的文本内容,每次请求的 API key,每次请求的输入 token,输出 token 数量。

## Docker Local Deployment

Start the container
Expand Down
11 changes: 10 additions & 1 deletion models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from io import IOBase
from pydantic import BaseModel, Field, model_validator
from typing import List, Dict, Optional, Union, Tuple, Literal
from typing import List, Dict, Optional, Union, Tuple, Literal, Any
from log_config import logger

class FunctionParameter(BaseModel):
Expand Down Expand Up @@ -61,6 +61,14 @@ class ToolChoice(BaseModel):
class BaseRequest(BaseModel):
request_type: Optional[Literal["chat", "image", "audio", "moderation"]] = Field(default=None, exclude=True)

class JsonSchema(BaseModel):
name: str
schema: Dict[str, Any]

class ResponseFormat(BaseModel):
type: Literal["text", "json_object", "json_schema"]
json_schema: Optional[JsonSchema] = None

class RequestModel(BaseRequest):
model: str
messages: List[Message]
Expand All @@ -77,6 +85,7 @@ class RequestModel(BaseRequest):
user: Optional[str] = None
tool_choice: Optional[Union[str, ToolChoice]] = None
tools: Optional[List[Tool]] = None
response_format: Optional[ResponseFormat] = None # 新增字段

def get_last_text_message(self) -> Optional[str]:
for message in reversed(self.messages):
Expand Down

0 comments on commit 599e110

Please sign in to comment.