objectiveai_api/ensemble/
client.rs1use crate::ctx;
4use std::sync::Arc;
5
6pub struct Client<CTXEXT, FENS, RTRVL> {
11 pub ensemble_fetcher: Arc<super::fetcher::CachingFetcher<CTXEXT, FENS>>,
13 pub retrieval_client: Arc<RTRVL>,
15 pub _ctx_ext: std::marker::PhantomData<CTXEXT>,
17}
18
19impl<CTXEXT, FENS, RTRVL> Client<CTXEXT, FENS, RTRVL> {
20 pub fn new(
22 ensemble_fetcher: Arc<
23 super::fetcher::CachingFetcher<CTXEXT, FENS>,
24 >,
25 retrieval_client: Arc<RTRVL>,
26 ) -> Self {
27 Self {
28 ensemble_fetcher,
29 retrieval_client,
30 _ctx_ext: std::marker::PhantomData,
31 }
32 }
33}
34
35impl<CTXEXT, FENS, RTRVL> Client<CTXEXT, FENS, RTRVL>
36where
37 CTXEXT: Send + Sync + 'static,
38 FENS: super::fetcher::Fetcher<CTXEXT>
39 + Send
40 + Sync
41 + 'static,
42 RTRVL: super::retrieval_client::Client<CTXEXT> + Send + Sync + 'static,
43{
44 pub async fn list(
46 &self,
47 ctx: ctx::Context<CTXEXT>,
48 ) -> Result<
49 objectiveai::ensemble::response::ListEnsemble,
50 objectiveai::error::ResponseError,
51 > {
52 self.retrieval_client.list(ctx).await
53 }
54
55 pub async fn get(
59 &self,
60 ctx: ctx::Context<CTXEXT>,
61 id: &str,
62 ) -> Result<
63 objectiveai::ensemble::response::GetEnsemble,
64 objectiveai::error::ResponseError,
65 > {
66 self.ensemble_fetcher
67 .fetch(ctx, id)
68 .await?
69 .ok_or_else(|| objectiveai::error::ResponseError {
70 code: 404,
71 message: serde_json::json!({
72 "kind": "ensemble",
73 "error": "Ensemble not found"
74 }),
75 })
76 .map(|(inner, created)| {
77 objectiveai::ensemble::response::GetEnsemble { created, inner }
78 })
79 }
80
81 pub async fn get_usage(
83 &self,
84 ctx: ctx::Context<CTXEXT>,
85 id: &str,
86 ) -> Result<
87 objectiveai::ensemble::response::UsageEnsemble,
88 objectiveai::error::ResponseError,
89 > {
90 self.retrieval_client.get_usage(ctx, id).await
91 }
92}