mod private
{
use crate::error::{ OpenAiCompatError, Result };
use crate::{ Client, OpenAiCompatEnvironment };
use std::sync::Arc;
use tokio::runtime::Runtime;
#[ derive( Debug ) ]
pub struct SyncClient< E >
where
E : OpenAiCompatEnvironment,
{
client : Client< E >,
runtime : Arc< Runtime >,
}
impl< E > SyncClient< E >
where
E : OpenAiCompatEnvironment,
{
#[ inline ]
pub fn new( client : Client< E > ) -> Result< Self >
{
let runtime = Runtime::new()
.map_err( | e | OpenAiCompatError::Environment( e.to_string() ) )?;
Ok( Self { client, runtime : Arc::new( runtime ) } )
}
#[ inline ]
pub fn post< I, O >( &self, path : &str, body : &I ) -> Result< O >
where
I : serde::Serialize,
O : serde::de::DeserializeOwned,
{
self.runtime.block_on( self.client.post( path, body ) )
}
}
}
crate::mod_interface!
{
exposed use
{
SyncClient,
};
}