fix: prevent abort in local inference (#7633)

Signed-off-by: Kube Cat <cat@kubecat.io>
Co-authored-by: Kube Cat <cat@kubecat.io>
This commit is contained in:
KubeCat
2026-03-04 15:07:28 +01:00
committed by GitHub
parent 1285b31ce6
commit dafc4db7b4
4 changed files with 95 additions and 52 deletions
@@ -359,10 +359,19 @@ pub(super) fn generate_with_emulated_tools(
ctx: &mut GenerationContext<'_>,
code_mode_enabled: bool,
) -> Result<(), ProviderError> {
// Use oaicompat variant — its C++ wrapper catches exceptions that would
// otherwise abort the process when other native libs disturb the C++ ABI.
let prompt = ctx
.loaded
.model
.apply_chat_template(&ctx.loaded.template, ctx.chat_messages, true)
.apply_chat_template_with_tools_oaicompat(
&ctx.loaded.template,
ctx.chat_messages,
None, // no tools for emulated path
None, // no json_schema
true, // add_generation_prompt
)
.map(|r| r.prompt)
.map_err(|e| {
ProviderError::ExecutionError(format!("Failed to apply chat template: {}", e))
})?;