feat: add client.embeddings_async() method

This commit is contained in:
Ivan Gabriele
2024-03-04 06:39:21 +01:00
parent b69f7c617c
commit 3c228914f7
3 changed files with 68 additions and 4 deletions

View File

@@ -89,6 +89,22 @@ impl Client {
}
}
pub async fn embeddings_async(
&self,
model: EmbedModel,
input: Vec<String>,
options: Option<EmbeddingRequestOptions>,
) -> Result<EmbeddingResponse, ApiError> {
let request = EmbeddingRequest::new(model, input, options);
let response = self.post_async("/embeddings", &request).await?;
let result = response.json::<EmbeddingResponse>().await;
match result {
Ok(response) => Ok(response),
Err(error) => Err(self.to_api_error(error)),
}
}
pub fn list_models(&self) -> Result<ModelListResponse, ApiError> {
let response = self.get_sync("/models")?;
let result = response.json::<ModelListResponse>();