rig_core/providers/venice/
extension.rs1use serde::{Deserialize, Serialize};
18use serde_json::Value;
19
20use crate::completion::provider_options::reply_field;
21use crate::completion::{ExtensionOptions, ProviderExtension, ReplyExtras};
22use crate::message::Api;
23
24#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
26pub struct VeniceExt;
27
28impl ProviderExtension for VeniceExt {
29 const PROVIDER: &'static str = super::PROVIDER_NAME;
30 type Options = VeniceOptions;
31 type Extras = VeniceExtras;
32}
33
34#[non_exhaustive]
39#[derive(Clone, Debug, Default, PartialEq, Serialize)]
40pub struct VeniceOptions {
41 #[serde(rename = "*")]
43 pub shared: VeniceShared,
44}
45
46#[non_exhaustive]
48#[derive(Clone, Debug, Default, PartialEq, Serialize)]
49pub struct VeniceShared {
50 #[serde(skip_serializing_if = "Option::is_none")]
52 pub venice_parameters: Option<VeniceParameters>,
53 #[serde(skip_serializing_if = "Option::is_none")]
55 pub prompt_cache_key: Option<String>,
56}
57
58impl VeniceOptions {
59 pub fn new() -> Self {
61 Self::default()
62 }
63
64 pub fn venice_parameters(mut self, parameters: VeniceParameters) -> Self {
66 self.shared.venice_parameters = Some(parameters);
67 self
68 }
69
70 pub fn prompt_cache_key(mut self, key: impl Into<String>) -> Self {
72 self.shared.prompt_cache_key = Some(key.into());
73 self
74 }
75
76 fn with_parameters(mut self, set: impl FnOnce(VeniceParameters) -> VeniceParameters) -> Self {
78 let parameters = self.shared.venice_parameters.take().unwrap_or_default();
79 self.shared.venice_parameters = Some(set(parameters));
80 self
81 }
82
83 pub fn character_slug(self, slug: impl Into<String>) -> Self {
86 self.with_parameters(|parameters| parameters.character_slug(slug))
87 }
88
89 pub fn strip_thinking_response(self, strip: bool) -> Self {
92 self.with_parameters(|parameters| parameters.strip_thinking_response(strip))
93 }
94
95 pub fn enable_web_search(self, mode: WebSearchMode) -> Self {
97 self.with_parameters(|parameters| parameters.enable_web_search(mode))
98 }
99
100 pub fn enable_web_citations(self, enable: bool) -> Self {
103 self.with_parameters(|parameters| parameters.enable_web_citations(enable))
104 }
105
106 pub fn include_venice_system_prompt(self, include: bool) -> Self {
109 self.with_parameters(|parameters| parameters.include_venice_system_prompt(include))
110 }
111}
112
113impl ExtensionOptions for VeniceOptions {
114 type Ext = VeniceExt;
115}
116
117#[non_exhaustive]
119#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
120#[serde(rename_all = "lowercase")]
121pub enum WebSearchMode {
122 Off,
124 On,
126 Auto,
128}
129
130#[non_exhaustive]
133#[derive(Clone, Debug, Default, PartialEq, Serialize)]
134pub struct VeniceParameters {
135 #[serde(skip_serializing_if = "Option::is_none")]
137 pub character_slug: Option<String>,
138 #[serde(skip_serializing_if = "Option::is_none")]
140 pub strip_thinking_response: Option<bool>,
141 #[serde(skip_serializing_if = "Option::is_none")]
143 pub enable_web_search: Option<WebSearchMode>,
144 #[serde(skip_serializing_if = "Option::is_none")]
146 pub enable_web_scraping: Option<bool>,
147 #[serde(skip_serializing_if = "Option::is_none")]
149 pub enable_x_search: Option<bool>,
150 #[serde(skip_serializing_if = "Option::is_none")]
152 pub enable_web_citations: Option<bool>,
153 #[serde(skip_serializing_if = "Option::is_none")]
155 pub include_search_results_in_stream: Option<bool>,
156 #[serde(skip_serializing_if = "Option::is_none")]
158 pub return_search_results_as_documents: Option<bool>,
159 #[serde(skip_serializing_if = "Option::is_none")]
161 pub include_venice_system_prompt: Option<bool>,
162}
163
164impl VeniceParameters {
165 pub fn new() -> Self {
167 Self::default()
168 }
169
170 pub fn character_slug(mut self, slug: impl Into<String>) -> Self {
172 self.character_slug = Some(slug.into());
173 self
174 }
175
176 pub fn strip_thinking_response(mut self, strip: bool) -> Self {
178 self.strip_thinking_response = Some(strip);
179 self
180 }
181
182 pub fn enable_web_search(mut self, mode: WebSearchMode) -> Self {
184 self.enable_web_search = Some(mode);
185 self
186 }
187
188 pub fn enable_web_scraping(mut self, enable: bool) -> Self {
190 self.enable_web_scraping = Some(enable);
191 self
192 }
193
194 pub fn enable_x_search(mut self, enable: bool) -> Self {
196 self.enable_x_search = Some(enable);
197 self
198 }
199
200 pub fn enable_web_citations(mut self, enable: bool) -> Self {
202 self.enable_web_citations = Some(enable);
203 self
204 }
205
206 pub fn include_search_results_in_stream(mut self, include: bool) -> Self {
208 self.include_search_results_in_stream = Some(include);
209 self
210 }
211
212 pub fn return_search_results_as_documents(mut self, as_documents: bool) -> Self {
214 self.return_search_results_as_documents = Some(as_documents);
215 self
216 }
217
218 pub fn include_venice_system_prompt(mut self, include: bool) -> Self {
220 self.include_venice_system_prompt = Some(include);
221 self
222 }
223}
224
225#[non_exhaustive]
227#[derive(Clone, Debug, Default, PartialEq)]
228pub struct VeniceExtras {
229 pub venice_parameters: Option<VeniceParametersEcho>,
231 pub cost: Option<VeniceCost>,
233}
234
235#[non_exhaustive]
238#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
239pub struct VeniceParametersEcho {
240 #[serde(default)]
242 pub character_slug: Option<String>,
243 #[serde(default)]
245 pub strip_thinking_response: Option<bool>,
246 #[serde(default)]
248 pub disable_thinking: Option<bool>,
249 #[serde(default)]
251 pub enable_web_search: Option<WebSearchMode>,
252 #[serde(default)]
254 pub enable_web_scraping: Option<bool>,
255 #[serde(default)]
257 pub enable_x_search: Option<bool>,
258 #[serde(default)]
260 pub enable_web_citations: Option<bool>,
261 #[serde(default)]
263 pub include_search_results_in_stream: Option<bool>,
264 #[serde(default)]
266 pub return_search_results_as_documents: Option<bool>,
267 #[serde(default)]
269 pub include_venice_system_prompt: Option<bool>,
270 #[serde(default)]
272 pub enable_e2ee: Option<bool>,
273 #[serde(default)]
275 pub web_search_citations: Option<Vec<WebSearchCitation>>,
276}
277
278#[non_exhaustive]
280#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize)]
281pub struct WebSearchCitation {
282 #[serde(default)]
284 pub title: Option<String>,
285 #[serde(default)]
287 pub url: Option<String>,
288 #[serde(default)]
290 pub content: Option<String>,
291 #[serde(default)]
293 pub date: Option<String>,
294}
295
296#[non_exhaustive]
298#[derive(Clone, Copy, Debug, Default, PartialEq, Deserialize)]
299pub struct VeniceCost {
300 #[serde(default)]
302 pub usd: Option<f64>,
303 #[serde(default)]
305 pub diem: Option<f64>,
306}
307
308impl ReplyExtras for VeniceExtras {
309 fn from_reply(_api: &Api, raw: &Value) -> Result<Self, serde_json::Error> {
310 Ok(Self {
311 venice_parameters: reply_field(raw, "/venice_parameters")?,
312 cost: reply_field(raw, "/cost")?,
313 })
314 }
315}
316
317#[cfg(test)]
318mod tests;