Skip to content
Closed
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
31 changes: 12 additions & 19 deletions crates/tokenizer/src/encoders/kimi_k25_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//! function-by-function. Output must be byte-equal to the Python reference;
//! gated by golden tests in `tests/kimi_k25.rs`.

#![allow(clippy::unwrap_used)]

use std::{collections::HashMap, fmt::Write};

use anyhow::Result;
Expand Down Expand Up @@ -51,19 +49,14 @@ pub(crate) fn apply_kimi_k25_tools(

// Build owned kwargs only when we have something to inject; otherwise
// delegate without allocating.
let owned: Option<HashMap<String, Value>> = match (params.template_kwargs, ts_str.as_ref()) {
(Some(existing), Some(ts)) => {
let mut m = existing.clone();
m.insert("tools_ts_str".to_string(), Value::String(ts.clone()));
Some(m)
}
(None, Some(ts)) => {
let mut m = HashMap::with_capacity(1);
m.insert("tools_ts_str".to_string(), Value::String(ts.clone()));
Some(m)
}
_ => None, // No tools → leave tools_ts_str undefined
};
let owned: Option<HashMap<String, Value>> = ts_str.map(|ts| {
let mut m = match params.template_kwargs {
Some(existing) => existing.clone(),
None => HashMap::with_capacity(1),
};
m.insert("tools_ts_str".to_string(), Value::String(ts));
m
});

let new_params = ChatTemplateParams {
template_kwargs: owned.as_ref().or(params.template_kwargs),
Expand Down Expand Up @@ -119,7 +112,7 @@ fn openai_function_to_typescript(function: &Value) -> String {
def_str.push('\n');
}
}
write!(def_str, "interface {name} {body}").unwrap();
write!(def_str, "interface {name} {body}").expect("writing to a String is infallible");
interfaces.push(def_str);
}

Expand Down Expand Up @@ -260,7 +253,7 @@ impl BaseType {
.iter()
.map(|(k, v)| format!("{k}: {}", json_inline(v)))
.collect();
writeln!(out, "{indent}// {}", parts.join(", ")).unwrap();
writeln!(out, "{indent}// {}", parts.join(", ")).expect("writing to a String is infallible");
}
out
}
Expand Down Expand Up @@ -316,7 +309,7 @@ impl Parameter {
Value::Number(_) => d.to_string(),
_ => serde_json::to_string(d).unwrap_or_else(|_| "null".to_string()),
};
writeln!(out, "{indent}// Default: {repr}").unwrap();
writeln!(out, "{indent}// Default: {repr}").expect("writing to a String is infallible");
}
let opt_marker = if self.optional { "?" } else { "" };
write!(
Expand All @@ -325,7 +318,7 @@ impl Parameter {
self.name,
self.typ.to_typescript(indent, registry)
)
.unwrap();
.expect("writing to a String is infallible");
out
}
}
Expand Down
Loading