feat(llm): 添加 LLM 调用周期核心模块

新增 LLM 调用生命周期引擎,包含 Provider 抽象、OpenAI 兼容实现、
可重试机制及 Token 用量追踪。移除原有的占位测试代码。
添加所需的 Rust 依赖(tokio、reqwest、serde 等)。
This commit is contained in:
徐涛
2026-05-12 06:06:24 +08:00
parent b21e163be0
commit 91d32a6a82
10 changed files with 788 additions and 13 deletions
+15
View File
@@ -0,0 +1,15 @@
pub mod openai;
use crate::llm::error::LlmError;
use crate::llm::types::{ChatRequest, ChatResponse};
use async_trait::async_trait;
/// LLM Provider 抽象接口。
///
/// 所有具体的 LLM 后端实现(OpenAI、Anthropic、Azure 等)
/// 均需实现此 trait,以实现可插拔替换。
#[async_trait]
pub trait LlmProvider: Send + Sync {
/// 发送聊天请求并返回完整响应。
async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, LlmError>;
}