crate::ix!();
pub trait OpenAIConfigInterface = async_openai::config::Config;
#[derive(Debug)]
pub struct OpenAIClientHandle<E>
where
E: Debug + Send + Sync + From<OpenAIClientError>,
{
client: async_openai::Client<OpenAIConfig>,
_marker: std::marker::PhantomData<E>,
}
#[async_trait]
impl<E> LanguageModelClientInterface<E> for OpenAIClientHandle<E>
where
E: From<OpenAIClientError>
+ From<std::io::Error>
+ Debug
+ Send
+ Sync,
{
}
impl<E> OpenAIClientHandle<E>
where
E: Debug + Send + Sync + From<OpenAIClientError>, {
pub fn new() -> Arc<Self> {
info!("creating new OpenAI Client Handle");
let openai_api_key
= std::env::var("OPENAI_API_KEY")
.expect("OPENAI_API_KEY environment variable not set");
let config = OpenAIConfig::new().with_api_key(openai_api_key);
let client = async_openai::Client::with_config(config);
Arc::new(Self {
client,
_marker: std::marker::PhantomData::<E>,
})
}
delegate!{
to self.client {
pub fn batches(&self) -> async_openai::Batches<OpenAIConfig>;
pub fn files(&self) -> async_openai::Files<OpenAIConfig>;
pub fn chat(&self) -> async_openai::Chat<OpenAIConfig>;
}
}
}