pub mod client; pub mod prompt; pub mod classify; pub mod template; pub use client::{AiClient, AiProvider, StreamChunk}; pub use prompt::PromptEngine; pub use classify::Classifier; pub use template::{Template, TemplateManager, TemplateVariable}; use anyhow::Result; /// AI 服务错误类型 #[derive(Debug, thiserror::Error)] pub enum AiError { #[error("API 错误: {0}")] ApiError(String), #[error("网络错误: {0}")] NetworkError(String), #[error("认证失败: {0}")] AuthError(String), #[error("限流: 请稍后再试")] RateLimitError, #[error("配置错误: {0}")] ConfigError(String), #[error("模板错误: {0}")] TemplateError(String), #[error("其他错误: {0}")] Other(String), } impl From for AiError { fn from(err: reqwest::Error) -> Self { if err.is_timeout() { AiError::NetworkError("请求超时".to_string()) } else if err.is_connect() { AiError::NetworkError("连接失败".to_string()) } else { AiError::NetworkError(err.to_string()) } } } /// AI 服务结果 #[derive(Debug, Clone)] pub struct AiResult { /// 生成的文本内容 pub content: String, /// 使用的 Token 数量(估算) pub tokens_used: Option, /// 模型名称 pub model: String, /// 置信度评分(0.0 - 1.0) pub confidence: Option, } /// 分类结果 #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ClassificationResult { /// 主分类 pub category: String, /// 子分类 pub subcategory: Option, /// 标签列表 pub tags: Vec, /// 置信度评分(0.0 - 1.0) pub confidence: f64, /// AI 提供的推理说明 pub reasoning: Option, }