Restore entry labels in context tree: role, tool calls, memory keys
ConversationEntry::label() provides descriptive labels matching the old entry_sections format: - "Kent: what about..." / "Aria: [tool_call: memory_search, ...]" - "mem: [memory: key-name score:0.73]" - "dmn: [heartbeat]" / "system: [system prompt]" Uses config names (assistant_name, user_name) not generic "asst"/"user". Widget renderer uses label() instead of raw content preview. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
5523752a15
commit
a20f3e3642
2 changed files with 44 additions and 8 deletions
|
|
@ -347,6 +347,44 @@ impl ConversationEntry {
|
|||
matches!(self, Self::Log(_))
|
||||
}
|
||||
|
||||
/// Short description for the debug UI.
|
||||
pub fn label(&self) -> String {
|
||||
let cfg = crate::config::get();
|
||||
match self {
|
||||
Self::System(_) => "system: [system prompt]".to_string(),
|
||||
Self::Dmn(_) => "dmn: [heartbeat]".to_string(),
|
||||
Self::Log(text) => {
|
||||
let preview: String = text.chars().take(60).collect();
|
||||
format!("log: {}", preview.replace('\n', " "))
|
||||
}
|
||||
Self::Memory { key, score, .. } => {
|
||||
let role = "mem".to_string();
|
||||
match score {
|
||||
Some(s) => format!("{}: [memory: {} score:{:.1}]", role, key, s),
|
||||
None => format!("{}: [memory: {}]", role, key),
|
||||
}
|
||||
}
|
||||
Self::Message(m) => {
|
||||
let role = match m.role {
|
||||
Role::Assistant => cfg.assistant_name.clone(),
|
||||
Role::User => cfg.user_name.clone(),
|
||||
Role::Tool => "tool".to_string(),
|
||||
Role::System => "system".to_string(),
|
||||
};
|
||||
if let Some(tc) = &m.tool_calls {
|
||||
let names: Vec<_> = tc.iter().map(|c| c.function.name.as_str()).collect();
|
||||
format!("{}: [tool_call: {}]", role, names.join(", "))
|
||||
} else {
|
||||
let text = m.content_text();
|
||||
let preview: String = text.chars().take(60).collect();
|
||||
let preview = preview.replace('\n', " ");
|
||||
if text.len() > 60 { format!("{}: {}...", role, preview) }
|
||||
else { format!("{}: {}", role, preview) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a reference to the inner message.
|
||||
/// Panics on Log entries.
|
||||
pub fn message(&self) -> &Message {
|
||||
|
|
|
|||
|
|
@ -220,18 +220,16 @@ impl SectionTree {
|
|||
for ce in section.entries() {
|
||||
let entry_selected = self.selected == Some(*idx);
|
||||
let entry_expanded = self.expanded.contains(idx);
|
||||
let text = ce.entry.message().content_text();
|
||||
let preview: String = text.chars().take(60).collect();
|
||||
let preview = preview.replace('\n', " ");
|
||||
let label = if preview.len() < text.len() {
|
||||
format!(" {}...", preview)
|
||||
let text = if ce.entry.is_log() {
|
||||
String::new()
|
||||
} else {
|
||||
format!(" {}", preview)
|
||||
ce.entry.message().content_text().to_string()
|
||||
};
|
||||
let entry_marker = if text.len() > 60 {
|
||||
let has_content = text.len() > 0;
|
||||
let entry_marker = if has_content {
|
||||
if entry_expanded { "▼" } else { "▶" }
|
||||
} else { " " };
|
||||
let entry_label = format!(" {} {:>6} {}", entry_marker, ce.tokens, label);
|
||||
let entry_label = format!(" {} {:>6} {}", entry_marker, ce.tokens, ce.entry.label());
|
||||
let style = if entry_selected {
|
||||
Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue