use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Message { pub role: String, pub content: String, #[serde(skip_serializing_if = "Option::is_none")] pub tool_calls: Option>, } impl Message { pub fn system(content: impl ToString) -> Self { Self { role: "system".to_string(), content: content.to_string(), tool_calls: None, } } pub fn user(content: impl ToString) -> Self { Self { role: "user".to_string(), content: content.to_string(), tool_calls: None, } } pub fn assistant(content: impl ToString) -> Self { Self { role: "assistant".to_string(), content: content.to_string(), tool_calls: None, } } } #[derive(Debug, Serialize, Deserialize)] pub struct CompletionRequest { pub model: String, pub messages: Vec, #[serde(skip_serializing_if = "Option::is_none")] pub temperature: Option, #[serde(skip_serializing_if = "Option::is_none")] pub tools: Option>, } #[derive(Debug, Serialize, Deserialize)] pub struct Tool { pub name: String, pub description: String, pub parameters: serde_json::Value, } #[derive(Debug, Serialize, Deserialize)] pub struct CompletionResponse { pub id: String, pub object: String, pub created: u64, pub model: String, pub choices: Vec, } #[derive(Debug, Serialize, Deserialize)] pub struct Choice { pub index: u32, pub message: Message, pub finish_reason: String, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct ToolCall { pub id: String, #[serde(rename = "type")] pub _type: String, pub function: ToolFunction, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct ToolFunction { pub name: String, pub arguments: String, } #[derive(Debug, Serialize, Deserialize)] pub struct ToolResult { pub success: bool, pub contents: Vec, } #[derive(Debug, Serialize, Deserialize)] pub struct Content { pub content_type: String, pub body: String, } impl Content { pub fn text(content: impl ToString) -> Self { Self { content_type: "text/plain".to_string(), body: content.to_string(), } } }