//! Anthropic API 数据模型 //! //! 用于 Anthropic Messages API 的请求/响应格式转换 use serde::{Deserialize, Serialize}; use serde_json::Value; /// Anthropic 请求 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AnthropicRequest { pub model: String, pub messages: Vec, pub max_tokens: u32, #[serde(skip_serializing_if = "Option::is_none")] pub system: Option, // 可以是 String 或 Vec #[serde(skip_serializing_if = "Option::is_none")] pub temperature: Option, #[serde(skip_serializing_if = "Option::is_none")] pub stream: Option, #[serde(skip_serializing_if = "Option::is_none")] pub tools: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub tool_choice: Option, } /// Anthropic 消息 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AnthropicMessage { pub role: String, pub content: Value, // String 或 Vec } /// Anthropic 内容块 #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(tag = "type")] pub enum AnthropicContentBlock { #[serde(rename = "text")] Text { text: String }, #[serde(rename = "image")] Image { source: ImageSource }, #[serde(rename = "tool_use")] ToolUse { id: String, name: String, input: Value, }, #[serde(rename = "tool_result")] ToolResult { tool_use_id: String, content: Value }, } /// 图片来源 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ImageSource { #[serde(rename = "type")] pub source_type: String, pub media_type: String, pub data: String, } /// Anthropic 工具定义 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AnthropicTool { pub name: String, #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, pub input_schema: Value, } /// Anthropic 响应 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AnthropicResponse { pub id: String, #[serde(rename = "type")] pub response_type: String, pub role: String, pub content: Vec, pub model: String, #[serde(skip_serializing_if = "Option::is_none")] pub stop_reason: Option, #[serde(skip_serializing_if = "Option::is_none")] pub stop_sequence: Option, pub usage: AnthropicUsage, } /// Anthropic 响应内容 #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(tag = "type")] pub enum AnthropicResponseContent { #[serde(rename = "text")] Text { text: String }, #[serde(rename = "tool_use")] ToolUse { id: String, name: String, input: Value, }, } /// Anthropic 使用量 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AnthropicUsage { pub input_tokens: u32, pub output_tokens: u32, }