use serde::{Deserialize, Serialize};
use super::message::{ChatMessage, Role};
use super::tools::ToolCallDelta;
#[derive(Debug, Deserialize)]
pub struct AnthropicStreamEvent {
pub message: Option<AnthropicStreamMessage>,
pub delta: Option<AnthropicStreamDelta>,
}
#[derive(Debug, Deserialize)]
pub struct AnthropicStreamMessage {
pub id: Option<String>,
pub model: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct AnthropicStreamDelta {
#[serde(rename = "type")]
pub delta_type: Option<String>,
pub text: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatResponse {
pub id: String,
pub model: String,
pub choices: Vec<ChatChoice>,
pub usage: Option<Usage>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub citations: Option<Vec<String>>,
}
impl ChatResponse {
pub fn content(&self) -> Option<&str> {
self.choices.first().and_then(|c| c.message.content.as_str())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatChoice {
pub index: u32,
pub message: ChatMessage,
pub finish_reason: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Usage {
pub prompt_tokens: u32,
pub completion_tokens: u32,
pub total_tokens: u32,
}
#[derive(Debug, Clone, Deserialize)]
pub struct StreamChunk {
pub id: String,
pub model: String,
pub choices: Vec<StreamChoice>,
}
impl StreamChunk {
pub fn delta_content(&self) -> Option<&str> {
self.choices
.first()
.and_then(|c| c.delta.content.as_deref())
}
pub fn is_finished(&self) -> bool {
self.choices
.first()
.and_then(|c| c.finish_reason.as_deref())
.is_some()
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct StreamChoice {
pub index: u32,
pub delta: Delta,
pub finish_reason: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Delta {
pub role: Option<Role>,
pub content: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tool_calls: Option<Vec<ToolCallDelta>>,
}