7ef266e4a0
实现AI问答的function call功能,支持调用系统接口进行查询。 改动内容: 1. 数据库扩展: - 在ai_chat_messages表增加tool_calls和tool_call_id字段 - 创建数据库迁移文件 2. 模型和Schema更新: - AiChatMessage模型增加tool_calls(JSON)和tool_call_id字段 - AiChatMessageSummary schema增加对应字段 3. Function Call实现: - 定义4个可调用函数:query_tower_models、query_lines、query_users、query_system_params - 实现_execute_function处理函数调用并返回格式化结果 - 更新_call_openai_api支持tools参数 4. 消息流程更新: - 重构send_message支持完整的function call流程 - 流程:用户消息 -> AI请求function call -> 执行函数 -> AI基于结果回复 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
60 lines
1.3 KiB
Python
60 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from .user import UserPublic
|
|
|
|
|
|
class AiChatMessageSummary(BaseModel):
|
|
id: int
|
|
conversation_id: int
|
|
role: str
|
|
content: str
|
|
tool_calls: dict | None = None
|
|
tool_call_id: str | None = None
|
|
created_at: datetime
|
|
|
|
|
|
class AiChatConversationSummary(BaseModel):
|
|
id: int
|
|
title: str
|
|
user_id: str
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
user: UserPublic | None = None
|
|
message_count: int = 0
|
|
|
|
|
|
class AiChatConversationDetail(BaseModel):
|
|
id: int
|
|
title: str
|
|
user_id: str
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
user: UserPublic | None = None
|
|
messages: list[AiChatMessageSummary] = []
|
|
|
|
|
|
class AiChatConversationListResponse(BaseModel):
|
|
items: list[AiChatConversationSummary]
|
|
total: int
|
|
|
|
|
|
class AiChatConversationCreateRequest(BaseModel):
|
|
title: str = Field(default="新对话", min_length=1, max_length=256)
|
|
|
|
|
|
class AiChatConversationUpdateRequest(BaseModel):
|
|
title: str = Field(min_length=1, max_length=256)
|
|
|
|
|
|
class AiChatMessageSendRequest(BaseModel):
|
|
content: str = Field(min_length=1, max_length=20000)
|
|
|
|
|
|
class AiChatMessageResponse(BaseModel):
|
|
message: AiChatMessageSummary
|
|
reply: AiChatMessageSummary
|