Skip to main content

objectiveai_api/functions/retrieval_client/
objectiveai.rs

1//! ObjectiveAI API implementation of the retrieval client.
2
3use crate::ctx;
4use std::sync::Arc;
5
6/// Lists Functions and retrieves usage via the ObjectiveAI API.
7pub struct ObjectiveAiClient {
8    /// The HTTP client for API requests.
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_functions(
25        &self,
26        _ctx: ctx::Context<CTXEXT>,
27    ) -> Result<
28        objectiveai::functions::response::ListFunction,
29        objectiveai::error::ResponseError,
30    > {
31        objectiveai::functions::list_functions(&self.client)
32            .await
33            .map_err(|e| objectiveai::error::ResponseError::from(&e))
34    }
35
36    async fn get_function_usage(
37        &self,
38        _ctx: ctx::Context<CTXEXT>,
39        owner: &str,
40        repository: &str,
41        commit: Option<&str>,
42    ) -> Result<
43        objectiveai::functions::response::UsageFunction,
44        objectiveai::error::ResponseError,
45    > {
46        objectiveai::functions::get_function_usage(&self.client, owner, repository, commit)
47            .await
48            .map_err(|e| objectiveai::error::ResponseError::from(&e))
49    }
50}