llm/api/types.rs
1use serde::{Deserialize, Serialize};
2
3/// Request payload for chat completion API endpoint
4#[derive(Deserialize)]
5pub struct ChatRequest {
6 /// List of messages in the conversation
7 pub messages: Option<Vec<Message>>,
8 /// Model identifier in format "provider:model_name"
9 pub model: Option<String>,
10 /// Optional chain steps for multi-step processing
11 #[serde(default)]
12 pub steps: Vec<ChainStepRequest>,
13 /// Optional response transformation function
14 #[serde(default)]
15 pub response_transform: Option<String>,
16 /// Optional temperature parameter
17 #[serde(default)]
18 pub temperature: Option<f32>,
19 /// Optional max tokens parameter
20 #[serde(default)]
21 pub max_tokens: Option<u32>,
22}
23
24/// Chain step configuration for multi-step processing
25#[derive(Deserialize)]
26pub struct ChainStepRequest {
27 /// Provider ID for this step
28 pub provider_id: String,
29 /// Step identifier
30 pub id: String,
31 /// Template with variable substitution
32 pub template: String,
33 /// Optional temperature parameter
34 #[serde(default)]
35 pub temperature: Option<f32>,
36 /// Optional max tokens parameter
37 #[serde(default)]
38 pub max_tokens: Option<u32>,
39 /// Optional response transformation function
40 #[serde(default)]
41 pub response_transform: Option<String>,
42}
43
44/// Single message in a chat conversation
45#[derive(Deserialize, Serialize)]
46pub struct Message {
47 /// Role of the message sender ("user" or "assistant")
48 pub role: String,
49 /// Content of the message
50 pub content: String,
51}
52
53/// Response payload from chat completion API endpoint
54#[derive(Serialize)]
55pub struct ChatResponse {
56 /// Unique identifier for this completion
57 pub id: String,
58 /// Object type identifier
59 pub object: String,
60 /// Unix timestamp when response was created
61 pub created: u64,
62 /// Name of the model that generated the completion
63 pub model: String,
64 /// List of completion choices generated
65 pub choices: Vec<Choice>,
66}
67
68/// Single completion choice in a chat response
69#[derive(Serialize)]
70pub struct Choice {
71 /// Index of this choice in the list
72 pub index: usize,
73 /// Generated message for this choice
74 pub message: Message,
75 /// Reason why the model stopped generating
76 pub finish_reason: String,
77}