models.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """数据模型定义"""
  2. from pydantic import BaseModel, Field
  3. from typing import Dict, List, Optional
  4. from datetime import datetime
  5. class ChatRequest(BaseModel):
  6. """单个NPC对话请求"""
  7. npc_name: str = Field(..., description="NPC名称")
  8. message: str = Field(..., description="玩家消息")
  9. class Config:
  10. json_schema_extra = {
  11. "example": {
  12. "npc_name": "张三",
  13. "message": "你好,你在做什么?"
  14. }
  15. }
  16. class ChatResponse(BaseModel):
  17. """单个NPC对话响应"""
  18. npc_name: str = Field(..., description="NPC名称")
  19. npc_title: str = Field(..., description="NPC职位")
  20. message: str = Field(..., description="NPC回复")
  21. success: bool = Field(default=True, description="是否成功")
  22. timestamp: Optional[datetime] = Field(default_factory=datetime.now, description="时间戳")
  23. class Config:
  24. json_schema_extra = {
  25. "example": {
  26. "npc_name": "张三",
  27. "npc_title": "Python工程师",
  28. "message": "你好!我正在写代码,调试一个多智能体系统的bug。",
  29. "success": True
  30. }
  31. }
  32. class NPCInfo(BaseModel):
  33. """NPC信息"""
  34. name: str = Field(..., description="NPC名称")
  35. title: str = Field(..., description="NPC职位")
  36. location: str = Field(..., description="NPC位置")
  37. activity: str = Field(..., description="当前活动")
  38. available: bool = Field(default=True, description="是否可对话")
  39. class NPCStatusResponse(BaseModel):
  40. """NPC状态响应"""
  41. dialogues: Dict[str, str] = Field(..., description="NPC当前对话内容")
  42. last_update: Optional[datetime] = Field(None, description="上次更新时间")
  43. next_update_in: int = Field(..., description="下次更新倒计时(秒)")
  44. class Config:
  45. json_schema_extra = {
  46. "example": {
  47. "dialogues": {
  48. "张三": "终于把这个bug修复了,测试通过!",
  49. "李四": "下周的产品评审会需要准备一下资料。",
  50. "王五": "这个界面的配色方案还需要优化一下。"
  51. },
  52. "last_update": "2024-01-15T10:30:00",
  53. "next_update_in": 25
  54. }
  55. }
  56. class NPCListResponse(BaseModel):
  57. """NPC列表响应"""
  58. npcs: List[NPCInfo] = Field(..., description="NPC列表")
  59. total: int = Field(..., description="NPC总数")