Skip to content
Open
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
12 changes: 10 additions & 2 deletions rust/src/chat/src/renderer/harmony/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{AssistantMessageExt as _, ReasoningEffort};

const SYSTEM_START_DATE_ENV: &str = "VLLM_SYSTEM_START_DATE";
const HARMONY_SYSTEM_INSTRUCTIONS_ENV: &str = "VLLM_GPT_OSS_HARMONY_SYSTEM_INSTRUCTIONS";
const MAX_SYSTEM_IDENTITY_LENGTH: usize = 4096;

/// GPT-OSS renderer backed by the official Harmony encoding.
pub struct HarmonyChatRenderer {
Expand Down Expand Up @@ -238,9 +239,16 @@ fn system_content(
}

if let Some(instructions) = instructions.filter(|text| !text.is_empty()) {
let truncated = if instructions.len() > MAX_SYSTEM_IDENTITY_LENGTH {
let mut t = instructions[..MAX_SYSTEM_IDENTITY_LENGTH].to_string();
t.push_str("... [truncated]");
t
} else {
instructions.to_string()
};
let model_identity = match content.model_identity.as_deref() {
Some(identity) if !identity.is_empty() => format!("{identity}\n{instructions}"),
_ => instructions.to_string(),
Some(identity) if !identity.is_empty() => format!("{identity}\n{truncated}"),
_ => truncated,
};
content = content.with_model_identity(model_identity);
}
Expand Down
Loading