feat(llm): 添加 LLM 调用周期核心模块
新增 LLM 调用生命周期引擎,包含 Provider 抽象、OpenAI 兼容实现、 可重试机制及 Token 用量追踪。移除原有的占位测试代码。 添加所需的 Rust 依赖(tokio、reqwest、serde 等)。
This commit is contained in:
@@ -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>;
|
||||
}
|
||||
Reference in New Issue
Block a user