Skip to main content

objectiveai_api/ensemble/fetcher/
objectiveai.rs

1//! ObjectiveAI ensemble fetcher implementation.
2
3use crate::ctx;
4use objectiveai::error::StatusError;
5use std::sync::Arc;
6
7/// Fetches ensembles from the ObjectiveAI HTTP API.
8pub struct ObjectiveAiFetcher {
9    /// The underlying HTTP client.
10    pub client: Arc<objectiveai::HttpClient>,
11}
12
13impl ObjectiveAiFetcher {
14    /// Creates a new ObjectiveAI ensemble fetcher.
15    pub fn new(client: Arc<objectiveai::HttpClient>) -> Self {
16        Self { client }
17    }
18}
19
20#[async_trait::async_trait]
21impl<CTXEXT> super::Fetcher<CTXEXT> for ObjectiveAiFetcher
22where
23    CTXEXT: Send + Sync + 'static,
24{
25    async fn fetch(
26        &self,
27        _ctx: ctx::Context<CTXEXT>,
28        id: &str,
29    ) -> Result<
30        Option<(objectiveai::ensemble::Ensemble, u64)>,
31        objectiveai::error::ResponseError,
32    > {
33        match objectiveai::ensemble::get_ensemble(&self.client, id).await {
34            Ok(ensemble) => Ok(Some((ensemble.inner, ensemble.created))),
35            Err(e) if e.status() == 404 => Ok(None),
36            Err(e) => Err(objectiveai::error::ResponseError::from(&e)),
37        }
38    }
39}