虚空咏者数据表设计
概述
虚空咏者使用 postgres 作为数据库,需要使用到的表格如下:
openai_clients
openai_clients 表主要记录的是虚空咏者系统所能使用的各类 openai 兼容 api 的服务端点机密信息。
字段名 | 类型 | 说明 | 示例 |
|---|---|---|---|
id | int(11) | 主键 | 1 |
desc | varchar(64) | 服务端点描述 | "openai" |
api_key | varchar(64) | 服务端点密钥 | "sk_xxx" |
endpoint | varchar(64) | 服务端点地址 | "https://api.openai.com" |
weight | int(11) | 服务端点权重 | 100 |
created_at | timestamp | 创建时间 | 2022-01-01 00:00:00 |
updated_at | timestamp | 更新时间 | 2022-01-01 00:00:00 |
索引:
desc作为索引,用作描述查询api_key作为索引,用作密钥查询endpoint作为索引,用作地址查询weight作为索引,用作权重查询created_at作为索引,用作时序查询updated_at作为索引,用作更新查询
openai_models
openai_models 表主要记录的是虚空咏者系统所能使用的各类 openai 兼容 api 的模型信息与定价信息。
字段名 | 类型 | 说明 | 示例 |
|---|---|---|---|
id | int(11) | 主键 | 1 |
client_id | int(11) | 可以使用的服务端点 id | 1 |
model | varchar(32) | 模型名称 | "gpt-4o" |
max_tokens | int(11) | 最大 token 数 | 2048 |
prompt_price | float(11) | prompt 的 token 价格 | 0.035 |
completion_price | float(11) | completion 的 token 价格 | 0.1 |
rpm_limit | int(11) | 每分钟请求限制 | 100 |
tpm_limit | int(11) | 每分钟 token 限制 | 100 |
created_at | timestamp | 创建时间 | 2022-01-01 00:00:00 |
updated_at | timestamp | 更新时间 | 2022-01-01 00:00:00 |
索引:
client_id作为索引,对应openai_clients表created_at作为索引,用作时序查询rpm_limit,tpm_limit作为索引,用作限制查询prompt_price,completion_price作为索引,用作价格查询model作为索引,用作模型查询max_tokens作为索引,用作 token 数查询updated_at作为索引,用作更新查询
openai_requests
openai_requests 表主要记录的是虚空咏者系统所能使用的各类 openai 兼容 api 的请求信息,包括请求内容和响应内容。
字段名 | 类型 | 说明 | 示例 |
|---|---|---|---|
id | int(11) | 主键 | 1 |
client_id | int(11) | 请求使用的服务端点 id | 1 |
model_id | int(11) | 请求使用的模型 id | 1 |
prompt_token_usage | int(11) | prompt 使用的 token 数 | 10 |
completion_token_usage | int(11) | completion 使用的 token 数 | 20 |
balance_cost | float(11) | 本次请求的花费 | 3.5 |
created_at | timestamp | 创建时间 | 2022-01-01 00:00:00 |
索引:
client_id,model_id作为索引,对应openai_clients,openai_models表created_at作为索引,用作时序查询balance_cost作为索引,用作花费查询
whisper_users
whisper_users 表主要记录的是虚空咏者系统的用户信息。
字段名 | 类型 | 说明 | 示例 |
|---|---|---|---|
id | int(11) | 主键 | 1 |
varchar(64) | (认证系统的)邮箱 | "user@example.com" | |
api_key | varchar(64) | 用户 api 密钥 | "sk_xxx" |
balance | decimal(11,6) | 用户余额 | 100 |
role | varchar(10) | 用户角色 | "user"/"system" |
allow_ip | varchar(64) | 允许访问的 ip 地址 | "192.168.1.1" |
created_at | timestamp | 创建时间 | 2022-01-01 00:00:00 |
updated_at | timestamp | 更新时间 | 2022-01-01 00:00:00 |
索引:
email作为索引,用作用户登录api_key作为索引,用作用户认证role作为索引,用作用户权限管理created_at作为索引,用作时序查询
whisper_user_permissions
whisper_user_permissions 表主要记录的是虚空咏者系统的用户权限信息。
字段名 | 类型 | 说明 | 示例 |
|---|---|---|---|
id | int(11) | 主键 | 1 |
user_id | int(11) | 用户 id | 1 |
client_id | int(11) | 用户可以使用的服务端点 id | 1 |
model_id | int(11) | 用户可以使用的模型 id | 1 |
created_at | timestamp | 创建时间 | 2022-01-01 00:00:00 |
索引:
client_id,model_id作为索引,对应openai_clients,openai_models表user_id作为索引,对应whisper_users表created_at作为索引,用作时序查询