-
Notifications
You must be signed in to change notification settings - Fork 677
/
Copy pathjson.py
68 lines (47 loc) · 2.22 KB
/
json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import datetime
from typing import Optional, Generic, TypeVar, get_args, Literal
from pydantic import model_validator, BaseModel, Field, create_model, RootModel
from api.enums import OpenaiWebChatModels, OpenaiApiChatModels
ModelT = TypeVar('ModelT', bound=OpenaiWebChatModels | OpenaiApiChatModels)
class OpenaiWebPerModelAskCount(RootModel[dict[str, int]]):
root: dict[str, int] = {model: 0 for model in list(OpenaiWebChatModels)}
@model_validator(mode="after")
@classmethod
def check(cls, m):
# 如果某个值缺失,则默认设置为0
for model in list(OpenaiWebChatModels):
if model not in m.root:
m.root[model] = 0
return m
@staticmethod
def unlimited():
return OpenaiWebPerModelAskCount(root={model: -1 for model in list(OpenaiWebChatModels)})
class OpenaiApiPerModelAskCount(RootModel[dict[str, int]]):
root: dict[str, int] = {model: 0 for model in list(OpenaiApiChatModels)}
@model_validator(mode="after")
@classmethod
def check(cls, m):
for model in list(OpenaiApiChatModels):
if model not in m.root:
m.root[model] = 0
return m
@staticmethod
def unlimited():
return OpenaiApiPerModelAskCount(root={model: -1 for model in list(OpenaiApiChatModels)})
class TimeWindowRateLimit(BaseModel):
window_seconds: int = Field(..., description="时间窗口大小,单位为秒")
max_requests: int = Field(..., description="在给定时间窗口内最多的请求次数")
class DailyTimeSlot(BaseModel):
start_time: datetime.time = Field(..., description="每天可使用的开始时间")
end_time: datetime.time = Field(..., description="每天可使用的结束时间")
class CustomOpenaiApiSettings(BaseModel):
url: Optional[str] = None
key: Optional[str] = None
class UploadedFileOpenaiWebInfo(BaseModel):
file_id: Optional[str] = None
use_case: Optional[Literal['my_files', 'multimodal'] | str] = None
upload_url: Optional[str] = Field(None, description="上传文件的url, 上传后应清空该字段")
download_url: Optional[str] = None
class UploadedFileExtraInfo(BaseModel):
width: Optional[int] = None
height: Optional[int] = None