Message Trimmer Demo

Demonstrating trim functions on real WildChat-1M conversations

About This Demo

This demo shows how the trimMiddle() function works in the LLM router architecture. The function trims messages by keeping the start (60%) and end (40%) with an ellipsis in between, reducing token count while preserving context for intent classification. Adjust the max length sliders below to see how different messages are trimmed.

Implementation (from src/lib/server/router/arch.ts)

// Trim assistant messages to reduce routing prompt size
if (m.role === "assistant") {
  return { ...m, content: trimMiddle(m.content, maxAssistantLength) };
}
// Trim previous user messages (latest preserved)
if (m.role === "user" && idx !== lastUserIndex) {
  return { ...m, content: trimMiddle(m.content, maxPrevUserLength) };
}

Loading conversations...