//! Domain entities for the LLM inference API. //! //! Pure data structs with no framework dependencies beyond serde. //! These represent the OpenAI-compatible API shapes used across all layers. use serde::{Deserialize, Serialize}; // ═══════════════════════════════════════════════════════════════ // REQUEST TYPES // ═══════════════════════════════════════════════════════════════ /// OpenAI-compatible chat completion request body. #[derive(Deserialize)] pub struct ChatRequest { pub model: String, pub messages: Vec, pub max_tokens: Option, #[serde(default)] pub temperature: Option, #[serde(default)] pub top_p: Option, #[serde(default)] pub top_k: Option, #[serde(default)] pub min_p: Option, #[serde(default)] pub frequency_penalty: Option, #[serde(default)] pub presence_penalty: Option, #[serde(default)] pub repeat_penalty: Option, #[serde(default)] pub seed: Option, #[serde(default)] pub stream: Option, #[serde(default)] pub stop: Option>, #[serde(default)] pub tools: Option>, #[serde(default)] pub tool_choice: Option, } /// A single message in the chat conversation. #[derive(Deserialize)] pub struct ChatMessage { pub role: String, pub content: Option, #[serde(default)] pub tool_calls: Option>, #[serde(default)] pub tool_call_id: Option, #[serde(default)] pub name: Option, } /// Tool/function definition for function calling. #[derive(Deserialize, Serialize, Clone)] pub struct ToolDef { #[serde(rename = "type")] pub tool_type: String, pub function: ToolFunction, } #[derive(Deserialize, Serialize, Clone)] pub struct ToolFunction { pub name: String, #[serde(default)] pub description: String, #[serde(default)] pub parameters: serde_json::Value, } // ═══════════════════════════════════════════════════════════════ // RESPONSE TYPES // ═══════════════════════════════════════════════════════════════ /// OpenAI-compatible chat completion response (non-streaming). #[derive(Serialize)] pub struct ChatResponse { pub id: String, pub object: String, pub created: i64, pub model: String, pub choices: Vec, pub usage: Usage, } #[derive(Serialize)] pub struct Choice { pub index: u32, pub message: ResponseMessage, pub finish_reason: String, } #[derive(Serialize)] pub struct ResponseMessage { pub role: String, pub content: Option, #[serde(skip_serializing_if = "Option::is_none")] pub tool_calls: Option>, } #[derive(Serialize)] pub struct Usage { pub prompt_tokens: u32, pub completion_tokens: u32, pub total_tokens: u32, } // ═══════════════════════════════════════════════════════════════ // TOOL CALL TYPES // ═══════════════════════════════════════════════════════════════ /// A tool call in responses or streaming deltas. #[derive(Serialize, Deserialize, Clone)] pub struct ToolCall { pub id: String, #[serde(rename = "type")] pub call_type: String, pub function: ToolCallFunction, } #[derive(Serialize, Deserialize, Clone)] pub struct ToolCallFunction { pub name: String, pub arguments: String, } /// For parsing tool calls from message history (has extra fields). #[derive(Deserialize, Clone)] pub struct ToolCallResponse { pub id: String, #[serde(rename = "type")] pub call_type: String, pub function: ToolCallFunction, } // ═══════════════════════════════════════════════════════════════ // SSE (STREAMING) TYPES // ═══════════════════════════════════════════════════════════════ /// Server-Sent Event chunk for streaming responses. #[derive(Serialize)] pub struct SseChunk { pub id: String, pub object: String, pub created: i64, pub model: String, pub choices: Vec, } #[derive(Serialize)] pub struct SseChoice { pub index: u32, pub delta: SseDelta, #[serde(skip_serializing_if = "Option::is_none")] pub finish_reason: Option, } #[derive(Serialize)] pub struct SseDelta { #[serde(skip_serializing_if = "Option::is_none")] pub role: Option, #[serde(skip_serializing_if = "Option::is_none")] pub content: Option, #[serde(skip_serializing_if = "Option::is_none")] pub tool_calls: Option>, } // ═══════════════════════════════════════════════════════════════ // MODELS & HEALTH TYPES // ═══════════════════════════════════════════════════════════════ #[derive(Serialize)] pub struct ModelsResponse { pub object: String, pub data: Vec, } #[derive(Serialize)] pub struct ModelInfo { pub id: String, pub object: String, pub created: i64, pub owned_by: String, } #[derive(Serialize)] pub struct HealthResponse { pub status: String, pub model: String, }