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