use reqwest::header::HeaderMap;
use crate::{error::OpenAIError, RequestOptions};
use serde::Serialize;
pub trait AsyncTryFrom<T>: Sized {
type Error;
fn try_from(value: T) -> impl std::future::Future<Output = Result<Self, Self::Error>> + Send;
}
pub trait EventType {
fn event_type(&self) -> &'static str;
}
pub trait EventId {
fn event_id(&self) -> &str;
}
pub trait RequestOptionsBuilder: Sized {
fn options_mut(&mut self) -> &mut RequestOptions;
fn options(&self) -> &RequestOptions;
fn headers(mut self, headers: HeaderMap) -> Self {
self.options_mut().with_headers(headers);
self
}
fn header<K, V>(mut self, key: K, value: V) -> Result<Self, OpenAIError>
where
K: reqwest::header::IntoHeaderName,
V: TryInto<reqwest::header::HeaderValue>,
V::Error: Into<reqwest::header::InvalidHeaderValue>,
{
self.options_mut().with_header(key, value)?;
Ok(self)
}
fn query<Q: Serialize + ?Sized>(mut self, query: &Q) -> Result<Self, OpenAIError> {
self.options_mut().with_query(query)?;
Ok(self)
}
fn path<P: Into<String>>(mut self, path: P) -> Result<Self, OpenAIError> {
self.options_mut().with_path(path.into().as_str())?;
Ok(self)
}
}