use std::sync::Arc;
use chroma_types::{AttachedFunctionApiResponse, CollectionUuid};
use crate::{client::ChromaHttpClientError, ChromaHttpClient};
#[derive(Clone)]
pub struct ChromaAttachedFunction {
pub(crate) client: ChromaHttpClient,
pub(crate) attached_function: Arc<AttachedFunctionApiResponse>,
}
impl std::fmt::Debug for ChromaAttachedFunction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ChromaAttachedFunction")
.field("id", &self.attached_function.id)
.field("name", &self.attached_function.name)
.field("function_name", &self.attached_function.function_name)
.field(
"input_collection_id",
&self.attached_function.input_collection_id,
)
.field(
"output_collection",
&self.attached_function.output_collection_name,
)
.finish()
}
}
impl ChromaAttachedFunction {
pub fn id(&self) -> chroma_types::AttachedFunctionUuid {
self.attached_function.id
}
pub fn name(&self) -> &str {
&self.attached_function.name
}
pub fn function_name(&self) -> &str {
&self.attached_function.function_name
}
pub fn input_collection_id(&self) -> CollectionUuid {
self.attached_function.input_collection_id
}
pub fn output_collection(&self) -> &str {
&self.attached_function.output_collection_name
}
pub async fn add_input(
&self,
input_collection_id: CollectionUuid,
) -> Result<Self, ChromaHttpClientError> {
self.client
.add_attached_function_input(
self.attached_function.input_collection_id,
self.attached_function.name.clone(),
input_collection_id,
)
.await
}
}