use crate::Headers;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct EmbedOptions {
pub headers: Option<Headers>,
pub capture_raw_body: Option<bool>,
pub capture_usage: Option<bool>,
pub dimensions: Option<usize>,
pub encoding_format: Option<String>,
pub user: Option<String>,
pub embedding_type: Option<String>,
pub truncate: Option<String>,
}
impl EmbedOptions {
pub fn new() -> Self {
Self::default()
}
}
impl EmbedOptions {
pub fn with_headers(mut self, headers: Headers) -> Self {
self.headers = Some(headers);
self
}
pub fn with_capture_raw_body(mut self, capture: bool) -> Self {
self.capture_raw_body = Some(capture);
self
}
pub fn with_capture_usage(mut self, capture: bool) -> Self {
self.capture_usage = Some(capture);
self
}
pub fn with_dimensions(mut self, dimensions: usize) -> Self {
self.dimensions = Some(dimensions);
self
}
pub fn with_encoding_format(mut self, format: impl Into<String>) -> Self {
self.encoding_format = Some(format.into());
self
}
pub fn with_user(mut self, user: impl Into<String>) -> Self {
self.user = Some(user.into());
self
}
pub fn with_embedding_type(mut self, embedding_type: impl Into<String>) -> Self {
self.embedding_type = Some(embedding_type.into());
self
}
pub fn with_truncate(mut self, truncate: impl Into<String>) -> Self {
self.truncate = Some(truncate.into());
self
}
}
impl EmbedOptions {
pub fn headers(&self) -> Option<&Headers> {
self.headers.as_ref()
}
pub fn capture_raw_body(&self) -> bool {
self.capture_raw_body.unwrap_or(false)
}
pub fn capture_usage(&self) -> bool {
self.capture_usage.unwrap_or(true)
}
pub fn dimensions(&self) -> Option<usize> {
self.dimensions
}
pub fn encoding_format(&self) -> Option<&str> {
self.encoding_format.as_deref()
}
pub fn user(&self) -> Option<&str> {
self.user.as_deref()
}
pub fn embedding_type(&self) -> Option<&str> {
self.embedding_type.as_deref()
}
pub fn truncate(&self) -> Option<&str> {
self.truncate.as_deref()
}
}
#[derive(Debug, Clone, Default)]
pub struct EmbedOptionsSet<'client, 'request> {
client_options: Option<&'client EmbedOptions>,
request_options: Option<&'request EmbedOptions>,
}
impl<'client, 'request> EmbedOptionsSet<'client, 'request> {
pub fn new() -> Self {
Self::default()
}
pub fn with_client_options(mut self, options: Option<&'client EmbedOptions>) -> Self {
self.client_options = options;
self
}
pub fn with_request_options(mut self, options: Option<&'request EmbedOptions>) -> Self {
self.request_options = options;
self
}
pub fn headers(&self) -> Option<&Headers> {
self.request_options
.and_then(|o| o.headers())
.or_else(|| self.client_options.and_then(|o| o.headers()))
}
pub fn capture_raw_body(&self) -> bool {
self.request_options
.map(|o| o.capture_raw_body())
.or_else(|| self.client_options.map(|o| o.capture_raw_body()))
.unwrap_or(false)
}
pub fn capture_usage(&self) -> bool {
self.request_options
.map(|o| o.capture_usage())
.or_else(|| self.client_options.map(|o| o.capture_usage()))
.unwrap_or(true)
}
pub fn dimensions(&self) -> Option<usize> {
self.request_options
.and_then(|o| o.dimensions())
.or_else(|| self.client_options.and_then(|o| o.dimensions()))
}
pub fn encoding_format(&self) -> Option<&str> {
self.request_options
.and_then(|o| o.encoding_format())
.or_else(|| self.client_options.and_then(|o| o.encoding_format()))
}
pub fn user(&self) -> Option<&str> {
self.request_options
.and_then(|o| o.user())
.or_else(|| self.client_options.and_then(|o| o.user()))
}
pub fn embedding_type(&self) -> Option<&str> {
self.request_options
.and_then(|o| o.embedding_type())
.or_else(|| self.client_options.and_then(|o| o.embedding_type()))
}
pub fn truncate(&self) -> Option<&str> {
self.request_options
.and_then(|o| o.truncate())
.or_else(|| self.client_options.and_then(|o| o.truncate()))
}
}