Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions src/llm/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,16 +824,7 @@ impl SpacebotModel {

/// Remap model name for providers that require a different format in API calls.
fn remap_model_name_for_api(&self) -> String {
if self.provider == "zai-coding-plan" {
// Z.AI Coding Plan API expects "zai/glm-5" not "glm-5"
let model_name = self
.model_name
.strip_prefix("zai/")
.unwrap_or(&self.model_name);
format!("zai/{model_name}")
} else {
self.model_name.clone()
}
remap_model_name_for_api(&self.provider, &self.model_name)
}

/// Generic OpenAI-compatible API call with optional bearer auth.
Expand Down Expand Up @@ -1526,6 +1517,18 @@ fn parse_openai_error_message(response_text: &str) -> Option<String> {
.map(ToOwned::to_owned)
}

fn remap_model_name_for_api(provider: &str, model_name: &str) -> String {
if provider == "zai-coding-plan" {
// Coding Plan endpoint expects plain model ids (e.g. "glm-5").
model_name
.strip_prefix("zai/")
.unwrap_or(model_name)
.to_string()
} else {
model_name.to_string()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -1568,4 +1571,20 @@ mod tests {
panic!("expected ToolCall");
}
}
#[test]
fn coding_plan_model_name_uses_plain_glm_id() {
assert_eq!(
remap_model_name_for_api("zai-coding-plan", "glm-5"),
"glm-5"
);
assert_eq!(
remap_model_name_for_api("zai-coding-plan", "zai/glm-5"),
"glm-5"
);
assert_eq!(
remap_model_name_for_api("openai", "gpt-4o-mini"),
"gpt-4o-mini"
);
Comment on lines +1584 to +1587

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor test hardening: could add a non-zai-coding-plan case where the model does have a zai/ prefix, to make sure we don’t accidentally strip prefixes for other providers later.

Suggested change
assert_eq!(
remap_model_name_for_api("openai", "gpt-4o-mini"),
"gpt-4o-mini"
);
assert_eq!(
remap_model_name_for_api("openai", "gpt-4o-mini"),
"gpt-4o-mini"
);
assert_eq!(
remap_model_name_for_api("openai", "zai/glm-5"),
"zai/glm-5"
);

assert_eq!(remap_model_name_for_api("openai", "zai/glm-5"), "zai/glm-5");
}
}
Loading