use crate::{ctx, vector};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct Client<CTXEXT, FVVOTE, FCVOTE> {
pub completion_votes_fetcher: Arc<FVVOTE>,
pub cache_vote_fetcher: Arc<FCVOTE>,
_marker: std::marker::PhantomData<CTXEXT>,
}
impl<CTXEXT, FVVOTE, FCVOTE> Client<CTXEXT, FVVOTE, FCVOTE> {
pub fn new(
completion_votes_fetcher: Arc<FVVOTE>,
cache_vote_fetcher: Arc<FCVOTE>,
) -> Self {
Self {
completion_votes_fetcher,
cache_vote_fetcher,
_marker: std::marker::PhantomData,
}
}
}
impl<CTXEXT, FVVOTE, FCVOTE> Client<CTXEXT, FVVOTE, FCVOTE>
where
CTXEXT: Send + Sync + 'static,
FVVOTE: vector::completions::completion_votes_fetcher::Fetcher<CTXEXT>
+ Send
+ Sync
+ 'static,
FCVOTE: vector::completions::cache_vote_fetcher::Fetcher<CTXEXT>
+ Send
+ Sync
+ 'static,
{
pub async fn fetch_completion_votes(
&self,
ctx: ctx::Context<CTXEXT, impl crate::ctx::persistent_cache::PersistentCacheClient>,
id: &str,
) -> Result<
objectiveai_sdk::vector::completions::cache::response::CompletionVotes,
objectiveai_sdk::error::ResponseError,
> {
let data = self.completion_votes_fetcher.fetch(ctx, id).await?;
Ok(objectiveai_sdk::vector::completions::cache::response::CompletionVotes {
data,
})
}
pub async fn fetch_cache_vote(
&self,
ctx: ctx::Context<CTXEXT, impl crate::ctx::persistent_cache::PersistentCacheClient>,
agent: &objectiveai_sdk::agent::InlineAgentBaseWithFallbacksOrRemote,
messages: &[objectiveai_sdk::agent::completions::message::Message],
responses: &[objectiveai_sdk::agent::completions::message::RichContent],
) -> Result<
objectiveai_sdk::vector::completions::cache::response::CacheVote,
objectiveai_sdk::error::ResponseError,
> {
let vote = self
.cache_vote_fetcher
.fetch(ctx, agent, messages, responses)
.await?;
Ok(
objectiveai_sdk::vector::completions::cache::response::CacheVote {
vote,
},
)
}
}