Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion crates/protocols/src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ pub enum ThinkingType {
Adaptive,
}

/// The `thinking` object shared by the Kimi and MiniMax chat APIs.
/// The `thinking` object shared by the Kimi, MiniMax and z.ai chat APIs.
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize, schemars::JsonSchema)]
pub struct ThinkingParam {
Expand All @@ -382,6 +382,9 @@ pub struct ThinkingParam {
pub keep: Option<String>,
/// Vendor effort level; more specific than the top-level `reasoning_effort`.
pub effort: Option<String>,
/// z.ai `clear_thinking`: whether the history's reasoning is dropped from

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit: The struct's doc comment a few lines up still says "The thinking object shared by the Kimi and MiniMax chat APIs" — with this z.ai-specific field added, the enumeration is stale. Consider updating it to mention z.ai (e.g. "shared by the Kimi, MiniMax and z.ai chat APIs") so the doc doesn't rot as soon as this merges.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 20b33bc: "shared by the Kimi, MiniMax and z.ai chat APIs".

/// the rendered prompt (`true`, the vendor default) or kept (`false`).
pub clear_thinking: Option<bool>,
}

impl ThinkingParam {
Expand Down Expand Up @@ -1074,6 +1077,7 @@ mod tests {
r#type: Some(ThinkingType::Disabled),
keep: Some("all".to_string()),
effort: Some("high".to_string()),
clear_thinking: None,
})
);
assert!(!request.other.contains_key("thinking"));
Expand Down
37 changes: 35 additions & 2 deletions crates/protocols/src/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

mod kimi;
mod minimax;
mod zai;

use crate::{
chat::{ChatCompletionRequest, ChatMessage},
Expand All @@ -32,6 +33,8 @@ pub enum ProviderProfile {
Kimi,
/// MiniMax contract (MiniMax-Provider-Verifier).
Minimax,
/// z.ai / GLM contract (providers-verifier `golden/zai`).
Zai,
}

impl ProviderProfile {
Expand All @@ -45,7 +48,9 @@ impl ProviderProfile {
) -> Box<dyn Iterator<Item = &'a Tool> + 'a> {
match self {
ProviderProfile::Kimi => Box::new(kimi::dynamic_tools(req)),
ProviderProfile::Minimax | ProviderProfile::OpenAi => Box::new(std::iter::empty()),
ProviderProfile::Minimax | ProviderProfile::Zai | ProviderProfile::OpenAi => {
Box::new(std::iter::empty())
}
}
}

Expand Down Expand Up @@ -81,6 +86,12 @@ impl ProviderProfile {
{
return ProviderProfile::Minimax;
}
if starts_with_ignore_ascii_case(segment, "glm")
|| starts_with_ignore_ascii_case(segment, "zai")
|| starts_with_ignore_ascii_case(segment, "z-ai")
{
return ProviderProfile::Zai;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}
ProviderProfile::OpenAi
}
Expand All @@ -99,7 +110,7 @@ impl ProviderProfile {
pub fn normalize_chat(self, req: &mut ChatCompletionRequest) {
match self {
ProviderProfile::Minimax => minimax::normalize_chat(req),
ProviderProfile::Kimi | ProviderProfile::OpenAi => {}
ProviderProfile::Kimi | ProviderProfile::Zai | ProviderProfile::OpenAi => {}
}
let mut dropped: Vec<&'static str> = Vec::new();
for message in &mut req.messages {
Expand Down Expand Up @@ -132,6 +143,7 @@ impl ProviderProfile {
}
match self {
ProviderProfile::Kimi => kimi::normalize_chat(req),
ProviderProfile::Zai => zai::normalize_chat(req),
ProviderProfile::OpenAi | ProviderProfile::Minimax => {}
}
}
Expand All @@ -147,6 +159,10 @@ impl ProviderProfile {
kimi::validate_chat(req)
}
ProviderProfile::Minimax => minimax::validate_chat(req),
ProviderProfile::Zai => {
reject_root(req)?;
zai::validate_chat(req)
}
ProviderProfile::OpenAi => reject_root(req),
}
}
Expand Down Expand Up @@ -218,6 +234,7 @@ mod tests {
fn only_the_minimax_profile_parses_tool_calls_without_tools() {
assert!(ProviderProfile::Minimax.parses_tool_calls_without_tools());
assert!(!ProviderProfile::Kimi.parses_tool_calls_without_tools());
assert!(!ProviderProfile::Zai.parses_tool_calls_without_tools());
assert!(!ProviderProfile::OpenAi.parses_tool_calls_without_tools());
}

Expand Down Expand Up @@ -249,12 +266,28 @@ mod tests {
"{model}"
);
}
for model in [
"glm-5.3-flash",
"GLM-5.3-Flash",
"zai-org/GLM-5.3-Flash",
"/models/glm-4.7",
"z-ai/glm-5",
] {
assert_eq!(
ProviderProfile::for_model(model),
ProviderProfile::Zai,
"{model}"
);
}
for model in [
"gpt-4o-mini",
"",
"/models/llama-3",
"my-kimi-alias",
"openai/gpt-4o",
"my-glm-alias",
// ChatGLM predates the z.ai chat contract.
"THUDM/chatglm3-6b",
] {
assert_eq!(
ProviderProfile::for_model(model),
Expand Down
Loading
Loading