1use reqwest::header::HeaderMap;
2
3use crate::{error::OpenAIError, RequestOptions};
4use serde::Serialize;
5
6pub trait AsyncTryFrom<T>: Sized {
7 type Error;
9
10 fn try_from(value: T) -> impl std::future::Future<Output = Result<Self, Self::Error>> + Send;
12}
13
14pub trait EventType {
16 fn event_type(&self) -> &'static str;
18}
19
20pub trait EventId {
22 fn event_id(&self) -> &str;
24}
25
26pub trait RequestOptionsBuilder: Sized {
28 fn options_mut(&mut self) -> &mut RequestOptions;
30
31 fn options(&self) -> &RequestOptions;
33
34 fn headers(mut self, headers: HeaderMap) -> Self {
36 self.options_mut().with_headers(headers);
37 self
38 }
39
40 fn header<K, V>(mut self, key: K, value: V) -> Result<Self, OpenAIError>
42 where
43 K: reqwest::header::IntoHeaderName,
44 V: TryInto<reqwest::header::HeaderValue>,
45 V::Error: Into<reqwest::header::InvalidHeaderValue>,
46 {
47 self.options_mut().with_header(key, value)?;
48 Ok(self)
49 }
50
51 fn query<Q: Serialize + ?Sized>(mut self, query: &Q) -> Result<Self, OpenAIError> {
53 self.options_mut().with_query(query)?;
54 Ok(self)
55 }
56
57 fn path<P: Into<String>>(mut self, path: P) -> Result<Self, OpenAIError> {
59 self.options_mut().with_path(path.into().as_str())?;
60 Ok(self)
61 }
62}