feat(ai): AiProvider trait 新增 generate_with_tools 默认方法 + UnsupportedOperation 错误变体

This commit is contained in:
iven
2026-05-18 02:29:19 +08:00
parent 01c75dbf5d
commit cad48a97d5
2 changed files with 19 additions and 0 deletions

View File

@@ -49,6 +49,9 @@ pub enum AiError {
#[error("AI 配置错误: {0}")]
ConfigError(String),
#[error("不支持的操作: {0}")]
UnsupportedOperation(String),
}
impl From<AiError> for AppError {

View File

@@ -27,4 +27,20 @@ pub trait AiProvider: Send + Sync {
/// 健康检查
async fn health_check(&self) -> AiResult<bool>;
/// Agent 专用生成方法 — 支持 Function Calling
/// 不支持 FC 的 Provider 使用默认实现(返回错误)
async fn generate_with_tools(
&self,
_messages: Vec<crate::dto::ChatMessage>,
_tools: Vec<crate::dto::ToolDefinition>,
_system_prompt: &str,
_model: &str,
_temperature: f32,
_max_tokens: u32,
) -> AiResult<crate::dto::AgentGenerateResponse> {
Err(crate::error::AiError::UnsupportedOperation(
"Function Calling not supported by this provider".into(),
))
}
}