修改docker-compose
This commit is contained in:
33
ai_service/schemas/ai_api_key.py
Normal file
33
ai_service/schemas/ai_api_key.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
# 基础模型(共享字段)
|
||||
class AIApiKeyBase(BaseModel):
|
||||
name: str = Field(..., max_length=255, description="密钥名称")
|
||||
platform: str = Field(..., max_length=100, description="平台(如openai)")
|
||||
api_key: str = Field(..., max_length=255, description="API密钥")
|
||||
url: Optional[str] = Field(None, max_length=255, description="自定义API地址")
|
||||
status: int = Field(0, description="状态(0=禁用,1=启用)")
|
||||
|
||||
# 创建请求模型(无需ID和时间字段)
|
||||
class AIApiKeyCreate(AIApiKeyBase):
|
||||
pass
|
||||
|
||||
# 更新请求模型(所有字段可选)
|
||||
class AIApiKeyUpdate(BaseModel):
|
||||
name: Optional[str] = Field(None, max_length=255)
|
||||
platform: Optional[str] = Field(None, max_length=100)
|
||||
api_key: Optional[str] = Field(None, max_length=255)
|
||||
url: Optional[str] = Field(None, max_length=255)
|
||||
status: Optional[int] = None
|
||||
|
||||
# 响应模型(包含数据库自动生成的字段)
|
||||
class AIApiKeyRead(AIApiKeyBase):
|
||||
id: int
|
||||
created_at: Optional[datetime]
|
||||
updated_at: Optional[datetime]
|
||||
|
||||
# 支持ORM模型直接转换为响应
|
||||
class Config:
|
||||
from_attributes = True # Pydantic v2用from_attributes,v1用orm_mode
|
||||
10
ai_service/schemas/ai_chat.py
Normal file
10
ai_service/schemas/ai_chat.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
class ChatCreate(BaseModel):
|
||||
pass
|
||||
|
||||
class Chat(ChatCreate):
|
||||
id: int
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
19
ai_service/schemas/base.py
Normal file
19
ai_service/schemas/base.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
class ReadSchemaType(BaseModel):
|
||||
"""
|
||||
所有响应模型的基类,包含公共字段和ORM转换配置
|
||||
"""
|
||||
id: int
|
||||
created_at: Optional[datetime] = None # 数据创建时间(可选,部分模型可能没有)
|
||||
updated_at: Optional[datetime] = None # 数据更新时间(可选)
|
||||
|
||||
class Config:
|
||||
"""
|
||||
配置Pydantic模型如何处理ORM对象:
|
||||
- from_attributes=True:支持直接从SQLAlchemy ORM模型转换(Pydantic v2)
|
||||
- 若使用Pydantic v1,需替换为 orm_mode=True
|
||||
"""
|
||||
from_attributes = True
|
||||
9
ai_service/schemas/user.py
Normal file
9
ai_service/schemas/user.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
class UserOut(BaseModel):
|
||||
id: int
|
||||
username: str
|
||||
email: str = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
Reference in New Issue
Block a user