///|
pub struct Client {
chat : ChatService
}
///|
pub struct ChatService {
completions : ChatCompletionsService
}
///|
priv struct Options {
http_client : &HttpClient
headers : Map[String, String]
base_url : String
}
///|
fn ChatService::new(options : Options) -> ChatService {
let completions = ChatCompletionsService::new(options)
ChatService::{ completions, }
}
///|
pub struct ChatCompletionsService {
priv options : Options
}
///|
fn ChatCompletionsService::new(options : Options) -> ChatCompletionsService {
ChatCompletionsService::{ options, }
}
///|
pub fn Client::new(
http_client~ : &HttpClient,
base_url? : String,
api_key? : String,
) -> Client {
let env_var = @sys.get_env_vars()
let base_url = match base_url {
Some(base_url) => base_url
None => "https://api.openai.com/v1"
}
let api_key = match api_key {
Some(api_key) => Some(api_key)
None =>
match env_var.get("OPENAI_API_KEY") {
Some(api_key) => Some(api_key)
None => None
}
}
let headers = {}
if api_key is Some(api_key) {
headers["Authorization"] = "Bearer \{api_key}"
}
let options = Options::{ http_client, base_url, headers }
Client::{ chat: ChatService::new(options) }
}