1use serde::{Deserialize, Serialize};
2use std::time::Duration;
3
4#[derive(Debug, Clone)]
6pub struct OllamaVisionConfig {
7 pub endpoint: String,
9 pub model: String,
11 pub timeout: Duration,
13 pub connect_timeout: Duration,
15 pub options: GenerateOptions,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct GenerateOptions {
22 pub num_predict: u32,
24 pub repeat_penalty: f32,
26 pub repeat_last_n: u32,
28 #[serde(skip_serializing_if = "Option::is_none")]
30 pub temperature: Option<f32>,
31 #[serde(skip_serializing_if = "Option::is_none")]
33 pub top_p: Option<f32>,
34}
35
36impl Default for GenerateOptions {
37 fn default() -> Self {
38 Self {
39 num_predict: 512,
40 repeat_penalty: 1.2,
41 repeat_last_n: 128,
42 temperature: None,
43 top_p: None,
44 }
45 }
46}
47
48impl Default for OllamaVisionConfig {
49 fn default() -> Self {
50 Self {
51 endpoint: "http://localhost:11434".to_string(),
52 model: "llava".to_string(),
53 timeout: Duration::from_secs(120),
54 connect_timeout: Duration::from_secs(10),
55 options: GenerateOptions::default(),
56 }
57 }
58}
59
60impl OllamaVisionConfig {
61 pub fn with_model(model: impl Into<String>) -> Self {
63 Self {
64 model: model.into(),
65 ..Default::default()
66 }
67 }
68
69 pub fn connect_timeout(mut self, timeout: Duration) -> Self {
71 self.connect_timeout = timeout;
72 self
73 }
74
75 pub fn endpoint(mut self, endpoint: impl Into<String>) -> Self {
77 self.endpoint = endpoint.into();
78 self
79 }
80
81 pub fn timeout(mut self, timeout: Duration) -> Self {
83 self.timeout = timeout;
84 self
85 }
86
87 pub fn options(mut self, options: GenerateOptions) -> Self {
89 self.options = options;
90 self
91 }
92}
93
94#[derive(Debug, Clone)]
96pub struct TagOptions {
97 pub prompt: Option<String>,
99 pub request_json_format: bool,
101 pub max_tags: usize,
104 pub max_tag_length: usize,
107 pub max_retries: u32,
109}
110
111impl Default for TagOptions {
112 fn default() -> Self {
113 Self {
114 prompt: None,
115 request_json_format: true,
116 max_tags: 30,
117 max_tag_length: 50,
118 max_retries: 2,
119 }
120 }
121}
122
123#[derive(Debug, Clone)]
125pub struct CaptionOptions {
126 pub prompt: Option<String>,
128 pub max_caption_length: usize,
131 pub max_retries: u32,
133}
134
135impl Default for CaptionOptions {
136 fn default() -> Self {
137 Self {
138 prompt: None,
139 max_caption_length: 500,
140 max_retries: 2,
141 }
142 }
143}