use crate::client::LettaClient;
use crate::error::LettaResult;
use crate::types::{EmbeddingModel, ListEmbeddingModelsParams, ListModelsParams, LlmConfig};
#[derive(Debug)]
pub struct ModelsApi<'a> {
client: &'a LettaClient,
}
impl<'a> ModelsApi<'a> {
pub fn new(client: &'a LettaClient) -> Self {
Self { client }
}
pub async fn list(&self, params: Option<ListModelsParams>) -> LettaResult<Vec<LlmConfig>> {
let mut query_params = Vec::new();
if let Some(params) = params {
if let Some(provider_categories) = params.provider_category {
for category in provider_categories {
query_params.push(("provider_category", category.to_string()));
}
}
if let Some(provider_name) = params.provider_name {
query_params.push(("provider_name", provider_name));
}
if let Some(provider_type) = params.provider_type {
query_params.push(("provider_type", provider_type));
}
}
if query_params.is_empty() {
self.client.get("v1/models").await
} else {
self.client.get_with_query("v1/models", &query_params).await
}
}
pub async fn list_embedding_models(
&self,
params: Option<ListEmbeddingModelsParams>,
) -> LettaResult<Vec<EmbeddingModel>> {
let mut query_params = Vec::new();
if let Some(params) = params {
if let Some(provider_categories) = params.provider_category {
for category in provider_categories {
query_params.push(("provider_category", category));
}
}
}
if query_params.is_empty() {
self.client.get("v1/models/embedding").await
} else {
self.client
.get_with_query("v1/models/embedding", &query_params)
.await
}
}
}
impl LettaClient {
pub fn models(&self) -> ModelsApi {
ModelsApi::new(self)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::client::ClientConfig;
#[test]
fn test_models_api_creation() {
let config = ClientConfig::new("http://localhost:8283").unwrap();
let client = LettaClient::new(config).unwrap();
let _api = ModelsApi::new(&client);
}
}