Skip to main content

objectiveai_api/ensemble/retrieval_client/
objectiveai.rs

1//! ObjectiveAI ensemble retrieval client implementation.
2
3use crate::ctx;
4use std::sync::Arc;
5
6/// Retrieval client that delegates to the ObjectiveAI HTTP API.
7pub struct ObjectiveAiClient {
8    /// The underlying HTTP client.
9    pub client: Arc<objectiveai::HttpClient>,
10}
11
12impl ObjectiveAiClient {
13    /// Creates a new ObjectiveAI retrieval client.
14    pub fn new(client: Arc<objectiveai::HttpClient>) -> Self {
15        Self { client }
16    }
17}
18
19#[async_trait::async_trait]
20impl<CTXEXT> super::Client<CTXEXT> for ObjectiveAiClient
21where
22    CTXEXT: Send + Sync + 'static,
23{
24    async fn list(
25        &self,
26        _ctx: ctx::Context<CTXEXT>,
27    ) -> Result<
28        objectiveai::ensemble::response::ListEnsemble,
29        objectiveai::error::ResponseError,
30    > {
31        objectiveai::ensemble::list_ensembles(&self.client)
32            .await
33            .map_err(|e| objectiveai::error::ResponseError::from(&e))
34    }
35
36    async fn get_usage(
37        &self,
38        _ctx: ctx::Context<CTXEXT>,
39        id: &str,
40    ) -> Result<
41        objectiveai::ensemble::response::UsageEnsemble,
42        objectiveai::error::ResponseError,
43    > {
44        objectiveai::ensemble::get_ensemble_usage(&self.client, id)
45            .await
46            .map_err(|e| objectiveai::error::ResponseError::from(&e))
47    }
48}