Skip to main content

oxide_agent/types/
mod.rs

1use serde::{Deserialize, Serialize};
2
3// ── Shared primitives ─────────────────────────────────────────────────────────
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6#[serde(rename_all = "lowercase")]
7pub enum Role {
8    System,
9    User,
10    Assistant,
11    Tool,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct Message {
16    pub role: Role,
17    pub content: String,
18    /// Present when the model calls a tool.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub tool_calls: Option<Vec<ToolCall>>,
21}
22
23// ── Tool / function calling ───────────────────────────────────────────────────
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct ToolCall {
27    pub function: FunctionCall,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct FunctionCall {
32    pub name: String,
33    pub arguments: serde_json::Value,
34}
35
36/// JSON-Schema description of a single tool, as expected by Ollama.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct ToolDefinition {
39    #[serde(rename = "type")]
40    pub kind: String, // always "function"
41    pub function: FunctionDefinition,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct FunctionDefinition {
46    pub name: String,
47    pub description: String,
48    pub parameters: serde_json::Value, // JSON Schema object
49}
50
51// ── /api/generate ─────────────────────────────────────────────────────────────
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct GenerateRequest {
55    pub model: String,
56    pub prompt: String,
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub system: Option<String>,
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub context: Option<Vec<u64>>,
61    #[serde(default)]
62    pub stream: bool,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct GenerateResponse {
67    pub model: String,
68    pub response: String,
69    pub done: bool,
70    /// Opaque context token array for multi-turn conversations.
71    #[serde(default)]
72    pub context: Vec<u64>,
73}
74
75// ── /api/chat ─────────────────────────────────────────────────────────────────
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
78pub struct ChatRequest {
79    pub model: String,
80    pub messages: Vec<Message>,
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub tools: Option<Vec<ToolDefinition>>,
83    #[serde(default)]
84    pub stream: bool,
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct ChatResponse {
89    pub model: String,
90    pub message: Message,
91    pub done: bool,
92}
93
94// ── /api/embed ─────────────────────────────────────────────────────────────────
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct EmbedRequest {
98    pub model: String,
99    pub input: EmbedInput,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum EmbedInput {
105    Single(String),
106    Batch(Vec<String>),
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct EmbedResponse {
111    pub model: String,
112    pub embeddings: Vec<Vec<f32>>,
113}
114
115// ── /api/tags ─────────────────────────────────────────────────────────────────
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct ModelInfo {
119    pub name: String,
120    pub size: u64,
121    pub digest: String,
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
125pub struct ListModelsResponse {
126    pub models: Vec<ModelInfo>,
127}