Skip to main content

llmix_rs/
types.rs

1use serde::{Deserialize, Serialize};
2use serde_json::{Map, Value};
3use std::collections::HashMap;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6#[serde(rename_all = "kebab-case")]
7pub enum CachingStrategy {
8    Native,
9    Gateway,
10    Disabled,
11    Redis,
12    RedisOrMemory,
13    Memory,
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
17#[serde(rename_all = "kebab-case")]
18pub enum ResponseCacheStrategy {
19    Redis,
20    RedisOrMemory,
21    Memory,
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
25#[serde(rename_all = "lowercase")]
26pub enum CacheHitTier {
27    L1,
28    L2,
29}
30
31#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
32pub struct ResponseCacheStats {
33    pub l1_size: usize,
34    pub l1_max: usize,
35    pub l2_enabled: bool,
36    pub l2_healthy: bool,
37    pub strategy: ResponseCacheStrategy,
38}
39
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
41#[serde(rename_all = "camelCase")]
42pub struct LlmUsage {
43    pub input_tokens: u32,
44    pub output_tokens: u32,
45    pub total_tokens: u32,
46}
47
48#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
49pub struct ProviderResult {
50    pub content: String,
51    pub model: String,
52    pub usage: LlmUsage,
53    #[serde(default, skip_serializing_if = "Option::is_none")]
54    pub headers: Option<HashMap<String, String>>,
55    #[serde(default, skip_serializing_if = "Option::is_none")]
56    pub tool_calls: Option<Vec<Value>>,
57}
58
59#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
60#[serde(rename_all = "camelCase")]
61pub struct DispatchContext {
62    pub provider: String,
63    pub model: String,
64    pub api_key: String,
65    pub messages: Vec<Value>,
66    pub kwargs: Map<String, Value>,
67    pub config: Value,
68}
69
70#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
71#[serde(rename_all = "camelCase")]
72pub struct CallInput {
73    pub config: Value,
74    pub messages: Vec<Value>,
75    #[serde(default, skip_serializing_if = "Option::is_none")]
76    pub singleflight_key: Option<String>,
77}
78
79#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81pub struct CallResponse {
82    pub content: String,
83    pub model: String,
84    pub provider: String,
85    pub usage: LlmUsage,
86    pub success: bool,
87    #[serde(default, skip_serializing_if = "Option::is_none")]
88    pub error: Option<String>,
89    #[serde(default, skip_serializing_if = "Option::is_none")]
90    pub thinking_content: Option<String>,
91    #[serde(default, skip_serializing_if = "Option::is_none")]
92    pub cache_hit: Option<CacheHitTier>,
93    #[serde(default, skip_serializing_if = "Option::is_none")]
94    pub tool_calls: Option<Vec<Value>>,
95}