From cad48a97d5107a23c612ae44c384070f3f0bafb1 Mon Sep 17 00:00:00 2001 From: iven Date: Mon, 18 May 2026 02:29:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(ai):=20AiProvider=20trait=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20generate=5Fwith=5Ftools=20=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20+=20UnsupportedOperation=20=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=8F=98=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/erp-ai/src/error.rs | 3 +++ crates/erp-ai/src/provider/mod.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/crates/erp-ai/src/error.rs b/crates/erp-ai/src/error.rs index 018c666..cf42f38 100644 --- a/crates/erp-ai/src/error.rs +++ b/crates/erp-ai/src/error.rs @@ -49,6 +49,9 @@ pub enum AiError { #[error("AI 配置错误: {0}")] ConfigError(String), + + #[error("不支持的操作: {0}")] + UnsupportedOperation(String), } impl From for AppError { diff --git a/crates/erp-ai/src/provider/mod.rs b/crates/erp-ai/src/provider/mod.rs index 5388dcc..3d4b431 100644 --- a/crates/erp-ai/src/provider/mod.rs +++ b/crates/erp-ai/src/provider/mod.rs @@ -27,4 +27,20 @@ pub trait AiProvider: Send + Sync { /// 健康检查 async fn health_check(&self) -> AiResult; + + /// Agent 专用生成方法 — 支持 Function Calling + /// 不支持 FC 的 Provider 使用默认实现(返回错误) + async fn generate_with_tools( + &self, + _messages: Vec, + _tools: Vec, + _system_prompt: &str, + _model: &str, + _temperature: f32, + _max_tokens: u32, + ) -> AiResult { + Err(crate::error::AiError::UnsupportedOperation( + "Function Calling not supported by this provider".into(), + )) + } }