Skip to main content

objectiveai_api/ensemble_llm/fetcher/
objectiveai.rs

1//! ObjectiveAI Ensemble LLM fetcher implementation.
2
3use crate::ctx;
4use objectiveai::error::StatusError;
5use std::sync::Arc;
6
7/// Fetches Ensemble LLMs 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 LLM 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_llm::EnsembleLlm, u64)>,
31        objectiveai::error::ResponseError,
32    > {
33        match objectiveai::ensemble_llm::get_ensemble_llm(&self.client, id)
34            .await
35        {
36            Ok(ensemble_llm) => Ok(Some((ensemble_llm.inner, ensemble_llm.created))),
37            Err(e) if e.status() == 404 => Ok(None),
38            Err(e) => Err(objectiveai::error::ResponseError::from(&e)),
39        }
40    }
41}