use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::completion::provider_options::reply_field;
use crate::completion::{ExtensionOptions, ProviderExtension, ReplyExtras};
use crate::message::Api;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct VeniceExt;
impl ProviderExtension for VeniceExt {
const PROVIDER: &'static str = super::PROVIDER_NAME;
type Options = VeniceOptions;
type Extras = VeniceExtras;
}
#[non_exhaustive]
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
pub struct VeniceOptions {
#[serde(rename = "*")]
pub shared: VeniceShared,
}
#[non_exhaustive]
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
pub struct VeniceShared {
#[serde(skip_serializing_if = "Option::is_none")]
pub venice_parameters: Option<VeniceParameters>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_key: Option<String>,
}
impl VeniceOptions {
pub fn new() -> Self {
Self::default()
}
pub fn venice_parameters(mut self, parameters: VeniceParameters) -> Self {
self.shared.venice_parameters = Some(parameters);
self
}
pub fn prompt_cache_key(mut self, key: impl Into<String>) -> Self {
self.shared.prompt_cache_key = Some(key.into());
self
}
fn with_parameters(mut self, set: impl FnOnce(VeniceParameters) -> VeniceParameters) -> Self {
let parameters = self.shared.venice_parameters.take().unwrap_or_default();
self.shared.venice_parameters = Some(set(parameters));
self
}
pub fn character_slug(self, slug: impl Into<String>) -> Self {
self.with_parameters(|parameters| parameters.character_slug(slug))
}
pub fn strip_thinking_response(self, strip: bool) -> Self {
self.with_parameters(|parameters| parameters.strip_thinking_response(strip))
}
pub fn enable_web_search(self, mode: WebSearchMode) -> Self {
self.with_parameters(|parameters| parameters.enable_web_search(mode))
}
pub fn enable_web_citations(self, enable: bool) -> Self {
self.with_parameters(|parameters| parameters.enable_web_citations(enable))
}
pub fn include_venice_system_prompt(self, include: bool) -> Self {
self.with_parameters(|parameters| parameters.include_venice_system_prompt(include))
}
}
impl ExtensionOptions for VeniceOptions {
type Ext = VeniceExt;
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum WebSearchMode {
Off,
On,
Auto,
}
#[non_exhaustive]
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
pub struct VeniceParameters {
#[serde(skip_serializing_if = "Option::is_none")]
pub character_slug: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub strip_thinking_response: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub enable_web_search: Option<WebSearchMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub enable_web_scraping: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub enable_x_search: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub enable_web_citations: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub include_search_results_in_stream: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub return_search_results_as_documents: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub include_venice_system_prompt: Option<bool>,
}
impl VeniceParameters {
pub fn new() -> Self {
Self::default()
}
pub fn character_slug(mut self, slug: impl Into<String>) -> Self {
self.character_slug = Some(slug.into());
self
}
pub fn strip_thinking_response(mut self, strip: bool) -> Self {
self.strip_thinking_response = Some(strip);
self
}
pub fn enable_web_search(mut self, mode: WebSearchMode) -> Self {
self.enable_web_search = Some(mode);
self
}
pub fn enable_web_scraping(mut self, enable: bool) -> Self {
self.enable_web_scraping = Some(enable);
self
}
pub fn enable_x_search(mut self, enable: bool) -> Self {
self.enable_x_search = Some(enable);
self
}
pub fn enable_web_citations(mut self, enable: bool) -> Self {
self.enable_web_citations = Some(enable);
self
}
pub fn include_search_results_in_stream(mut self, include: bool) -> Self {
self.include_search_results_in_stream = Some(include);
self
}
pub fn return_search_results_as_documents(mut self, as_documents: bool) -> Self {
self.return_search_results_as_documents = Some(as_documents);
self
}
pub fn include_venice_system_prompt(mut self, include: bool) -> Self {
self.include_venice_system_prompt = Some(include);
self
}
}
#[non_exhaustive]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct VeniceExtras {
pub venice_parameters: Option<VeniceParametersEcho>,
pub cost: Option<VeniceCost>,
}
#[non_exhaustive]
#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
pub struct VeniceParametersEcho {
#[serde(default)]
pub character_slug: Option<String>,
#[serde(default)]
pub strip_thinking_response: Option<bool>,
#[serde(default)]
pub disable_thinking: Option<bool>,
#[serde(default)]
pub enable_web_search: Option<WebSearchMode>,
#[serde(default)]
pub enable_web_scraping: Option<bool>,
#[serde(default)]
pub enable_x_search: Option<bool>,
#[serde(default)]
pub enable_web_citations: Option<bool>,
#[serde(default)]
pub include_search_results_in_stream: Option<bool>,
#[serde(default)]
pub return_search_results_as_documents: Option<bool>,
#[serde(default)]
pub include_venice_system_prompt: Option<bool>,
#[serde(default)]
pub enable_e2ee: Option<bool>,
#[serde(default)]
pub web_search_citations: Option<Vec<WebSearchCitation>>,
}
#[non_exhaustive]
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize)]
pub struct WebSearchCitation {
#[serde(default)]
pub title: Option<String>,
#[serde(default)]
pub url: Option<String>,
#[serde(default)]
pub content: Option<String>,
#[serde(default)]
pub date: Option<String>,
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, PartialEq, Deserialize)]
pub struct VeniceCost {
#[serde(default)]
pub usd: Option<f64>,
#[serde(default)]
pub diem: Option<f64>,
}
impl ReplyExtras for VeniceExtras {
fn from_reply(_api: &Api, raw: &Value) -> Result<Self, serde_json::Error> {
Ok(Self {
venice_parameters: reply_field(raw, "/venice_parameters")?,
cost: reply_field(raw, "/cost")?,
})
}
}
#[cfg(test)]
mod tests;