Initial commit: 000-platform project skeleton
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
12
backend/app/schemas/__init__.py
Normal file
12
backend/app/schemas/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
||||
"""请求/响应模型"""
|
||||
from .stats import AICallEventCreate, AICallEventResponse
|
||||
from .logs import LogCreate, LogResponse
|
||||
from .config import ConfigRead
|
||||
|
||||
__all__ = [
|
||||
"AICallEventCreate",
|
||||
"AICallEventResponse",
|
||||
"LogCreate",
|
||||
"LogResponse",
|
||||
"ConfigRead"
|
||||
]
|
||||
26
backend/app/schemas/config.py
Normal file
26
backend/app/schemas/config.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""配置相关Schema"""
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class ConfigRead(BaseModel):
|
||||
"""配置读取请求"""
|
||||
tenant_id: int = Field(..., description="租户ID")
|
||||
config_type: str = Field(..., description="配置类型")
|
||||
config_key: str = Field(..., description="配置键")
|
||||
|
||||
|
||||
class ConfigValue(BaseModel):
|
||||
"""配置值响应"""
|
||||
config_type: str
|
||||
config_key: str
|
||||
config_value: Optional[str]
|
||||
|
||||
|
||||
class ConfigWrite(BaseModel):
|
||||
"""配置写入"""
|
||||
tenant_id: int
|
||||
config_type: str
|
||||
config_key: str
|
||||
config_value: str
|
||||
encrypt: bool = False
|
||||
46
backend/app/schemas/logs.py
Normal file
46
backend/app/schemas/logs.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""日志相关Schema"""
|
||||
from datetime import datetime
|
||||
from typing import Optional, Literal
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class LogCreate(BaseModel):
|
||||
"""日志写入"""
|
||||
trace_id: Optional[str] = Field(None, description="链路追踪ID")
|
||||
tenant_id: Optional[int] = Field(None, description="租户ID")
|
||||
user_id: Optional[int] = Field(None, description="用户ID")
|
||||
app_code: str = Field(..., description="应用编码")
|
||||
log_type: Literal['request', 'error', 'app', 'biz', 'audit'] = Field(..., description="日志类型")
|
||||
level: Literal['debug', 'info', 'warn', 'error', 'fatal'] = Field('info', description="级别")
|
||||
category: Optional[str] = Field(None, description="分类")
|
||||
message: str = Field(..., description="消息")
|
||||
context: Optional[dict] = Field(None, description="上下文")
|
||||
method: Optional[str] = Field(None, description="HTTP方法")
|
||||
path: Optional[str] = Field(None, description="请求路径")
|
||||
status_code: Optional[int] = Field(None, description="HTTP状态码")
|
||||
duration_ms: Optional[int] = Field(None, description="耗时(ms)")
|
||||
error_type: Optional[str] = Field(None, description="错误类型")
|
||||
stack_trace: Optional[str] = Field(None, description="堆栈")
|
||||
action: Optional[str] = Field(None, description="操作")
|
||||
target_type: Optional[str] = Field(None, description="目标类型")
|
||||
target_id: Optional[str] = Field(None, description="目标ID")
|
||||
log_time: datetime = Field(..., description="日志时间")
|
||||
|
||||
|
||||
class LogResponse(BaseModel):
|
||||
"""日志响应"""
|
||||
id: int
|
||||
trace_id: Optional[str]
|
||||
app_code: str
|
||||
log_type: str
|
||||
level: str
|
||||
message: str
|
||||
log_time: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class BatchLogRequest(BaseModel):
|
||||
"""批量日志请求"""
|
||||
logs: list[LogCreate]
|
||||
42
backend/app/schemas/stats.py
Normal file
42
backend/app/schemas/stats.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""统计相关Schema"""
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class AICallEventCreate(BaseModel):
|
||||
"""AI调用事件上报"""
|
||||
tenant_id: int = Field(..., description="租户ID")
|
||||
user_id: Optional[int] = Field(None, description="用户ID")
|
||||
app_code: str = Field(..., description="应用编码")
|
||||
module_code: str = Field(..., description="模块编码")
|
||||
trace_id: Optional[str] = Field(None, description="链路追踪ID")
|
||||
prompt_name: str = Field(..., description="Prompt名称")
|
||||
model: str = Field(..., description="模型名称")
|
||||
input_tokens: int = Field(0, description="输入token")
|
||||
output_tokens: int = Field(0, description="输出token")
|
||||
cost: Decimal = Field(Decimal("0"), description="成本")
|
||||
latency_ms: int = Field(0, description="延迟(ms)")
|
||||
status: str = Field("success", description="状态")
|
||||
event_time: datetime = Field(..., description="事件时间")
|
||||
|
||||
|
||||
class AICallEventResponse(BaseModel):
|
||||
"""AI调用事件响应"""
|
||||
id: int
|
||||
tenant_id: int
|
||||
app_code: str
|
||||
prompt_name: str
|
||||
model: str
|
||||
input_tokens: int
|
||||
output_tokens: int
|
||||
event_time: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class BatchReportRequest(BaseModel):
|
||||
"""批量上报请求"""
|
||||
events: list[AICallEventCreate]
|
||||
Reference in New Issue
Block a user