const DEFAULT_HOST: &str = "https://api.z.ai";
fn default_root(endpoint_type: Option<&str>) -> String {
match endpoint_type {
Some("coding") => format!("{DEFAULT_HOST}/api/coding/paas/v4"),
_ => format!("{DEFAULT_HOST}/api/paas/v4"),
}
}
fn root(base_url: Option<&str>, endpoint_type: Option<&str>) -> String {
let configured = base_url.map(str::trim).filter(|s| !s.is_empty());
let Some(configured) = configured else {
return default_root(endpoint_type);
};
configured
.trim_end_matches('/')
.trim_end_matches("/chat/completions")
.trim_end_matches('/')
.to_string()
}
pub(crate) fn chat_url(base_url: Option<&str>, endpoint_type: Option<&str>) -> String {
format!("{}/chat/completions", root(base_url, endpoint_type))
}
pub(crate) fn models_url(base_url: Option<&str>, endpoint_type: Option<&str>) -> String {
format!("{}/models", root(base_url, endpoint_type))
}