feat(ai): AiProvider trait 新增 generate_with_tools 默认方法 + UnsupportedOperation 错误变体
This commit is contained in:
@@ -49,6 +49,9 @@ pub enum AiError {
|
|||||||
|
|
||||||
#[error("AI 配置错误: {0}")]
|
#[error("AI 配置错误: {0}")]
|
||||||
ConfigError(String),
|
ConfigError(String),
|
||||||
|
|
||||||
|
#[error("不支持的操作: {0}")]
|
||||||
|
UnsupportedOperation(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<AiError> for AppError {
|
impl From<AiError> for AppError {
|
||||||
|
|||||||
@@ -27,4 +27,20 @@ pub trait AiProvider: Send + Sync {
|
|||||||
|
|
||||||
/// 健康检查
|
/// 健康检查
|
||||||
async fn health_check(&self) -> AiResult<bool>;
|
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(),
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user