pub mod capabilities;
pub mod client;
pub mod conversions;
pub mod embedding_model;
pub mod extensions;
pub mod language_model;
pub mod settings;
use crate::core::DynamicModel;
use crate::core::capabilities::ModelName;
use crate::core::utils::validate_base_url;
use crate::error::Error;
use crate::providers::google::client::{GoogleEmbeddingOptions, GoogleOptions};
use crate::providers::google::settings::GoogleProviderSettings;
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct Google<M: ModelName> {
pub settings: GoogleProviderSettings,
pub(crate) lm_options: GoogleOptions,
pub(crate) embedding_options: GoogleEmbeddingOptions,
_phantom: std::marker::PhantomData<M>,
}
impl<M: ModelName> Google<M> {
pub fn builder() -> GoogleBuilder<M> {
GoogleBuilder::default()
}
}
impl Google<DynamicModel> {
pub fn model_name(name: impl Into<String>) -> Self {
let settings = GoogleProviderSettings::default();
let model_name = name.into();
let options = GoogleOptions::builder()
.model(model_name.clone())
.build()
.unwrap();
let embedding_options = GoogleEmbeddingOptions {
model: model_name.clone(),
requests: Vec::new(),
};
Self {
settings,
lm_options: options,
embedding_options,
_phantom: std::marker::PhantomData,
}
}
}
impl<M: ModelName> Default for Google<M> {
fn default() -> Self {
let settings = GoogleProviderSettings::default();
let options = GoogleOptions::builder()
.model(M::MODEL_NAME.to_string())
.build()
.unwrap();
let embedding_options = GoogleEmbeddingOptions {
model: M::MODEL_NAME.to_string(),
requests: Vec::new(),
};
Self {
settings,
lm_options: options,
embedding_options,
_phantom: std::marker::PhantomData,
}
}
}
pub struct GoogleBuilder<M: ModelName> {
settings: GoogleProviderSettings,
options: GoogleOptions,
_phantom: std::marker::PhantomData<M>,
}
impl<M: ModelName> Default for GoogleBuilder<M> {
fn default() -> Self {
let settings = GoogleProviderSettings::default();
let options = GoogleOptions::builder()
.model(M::MODEL_NAME.to_string())
.build()
.unwrap();
Self {
settings,
options,
_phantom: std::marker::PhantomData,
}
}
}
impl GoogleBuilder<DynamicModel> {
pub fn model_name(mut self, model_name: impl Into<String>) -> Self {
self.options.model = model_name.into();
self
}
}
impl<M: ModelName> GoogleBuilder<M> {
pub fn base_url(mut self, base_url: impl Into<String>) -> Self {
self.settings.base_url = base_url.into();
self
}
pub fn api_key(mut self, api_key: impl Into<String>) -> Self {
self.settings.api_key = api_key.into();
self
}
pub fn provider_name(mut self, provider_name: impl Into<String>) -> Self {
self.settings.provider_name = provider_name.into();
self
}
pub fn path(mut self, path: impl Into<String>) -> Self {
self.settings.path = Some(path.into());
self
}
pub fn build(self) -> Result<Google<M>, Error> {
let base_url = validate_base_url(&self.settings.base_url)?;
if self.settings.api_key.is_empty() {
return Err(Error::MissingField("api_key".to_string()));
}
let options = self.options;
let model_name = options.model.clone();
let embedding_options = GoogleEmbeddingOptions {
model: model_name,
requests: Vec::new(),
};
Ok(Google {
settings: GoogleProviderSettings {
base_url,
..self.settings
},
lm_options: options,
embedding_options,
_phantom: std::marker::PhantomData,
})
}
}
pub use capabilities::*;