-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_schema.py
More file actions
25 lines (22 loc) · 1.21 KB
/
Copy pathdata_schema.py
File metadata and controls
25 lines (22 loc) · 1.21 KB
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
from pydantic import BaseModel, Field
from typing import Dict, List, Any, Union, Optional
class TextClassifyRequest(BaseModel):
"""
请求格式
"""
request_id: Optional[str] = Field(..., description="请求id, 方便调试")
request_text: Union[str, List[str]] = Field(..., description="请求文本、字符串或列表")
# 如Optional[str]表示类型只能是字符串或者空,不能传数字、数组等
# Field(...)中的...代表必填,等价于不设默认值,key必须存在
# 虽然Optional(可以为None),但接口调用时必须带上request_id这个key,只是值可以传null
# Field(None)代表非必填,不传该字段也不会报错
class TextClassifyResponse(BaseModel):
"""
接口返回格式
"""
request_id: Optional[str] = Field(..., description="请求id")
request_text: Union[str, List[str]] = Field(..., description="请求文本、字符串或列表")
classify_result: Union[str, List[str]] = Field(..., description="分类结果")
classify_confidence: Union[float, List[float], None] = Field(None, description="分类置信度")
classify_time: float = Field(..., description="分类耗时")
error_msg: str = Field(..., description="异常信息")