Improved response logging
This commit is contained in:
parent
8a2f488d22
commit
7dd9daa2b9
1 changed files with 11 additions and 12 deletions
|
|
@ -607,19 +607,18 @@ impl ResponseParser {
|
|||
super::api::StreamToken::Done { usage } => {
|
||||
if let Some(ref mut f) = log_file {
|
||||
use std::io::Write;
|
||||
let tc_count = full_text.matches("<tool_call>").count();
|
||||
let ctx_tokens = agent.context.lock().await.tokens();
|
||||
let _ = writeln!(f, "done: {} chars, {} <tool_call> tags, ctx: {} tokens",
|
||||
full_text.len(), tc_count, ctx_tokens);
|
||||
if tc_count == 0 && full_text.len() > 0 {
|
||||
let ctx = agent.context.lock().await;
|
||||
let children = ctx.conversation().get(parser.branch_idx)
|
||||
.map(|n| n.children()).unwrap_or(&[]);
|
||||
let n_think = children.iter().filter(|c| matches!(c.leaf().map(|l| l.body()), Some(NodeBody::Thinking(_)))).count();
|
||||
let n_content = children.iter().filter(|c| matches!(c.leaf().map(|l| l.body()), Some(NodeBody::Content(_)))).count();
|
||||
let n_tool = children.iter().filter(|c| matches!(c.leaf().map(|l| l.body()), Some(NodeBody::ToolCall { .. }))).count();
|
||||
let _ = writeln!(f, "done: {} chars, {} content + {} think + {} tool_call, ctx: {} tokens",
|
||||
full_text.len(), n_content, n_think, n_tool, ctx.tokens());
|
||||
drop(ctx);
|
||||
if full_text.len() > 0 && n_content == 0 && n_tool == 0 {
|
||||
let end = full_text.floor_char_boundary(full_text.len().min(2000));
|
||||
let _ = writeln!(f, "full text:\n{}", &full_text[..end]);
|
||||
}
|
||||
for (i, part) in full_text.split("<tool_call>").enumerate() {
|
||||
if i > 0 {
|
||||
let end = part.floor_char_boundary(part.len().min(200));
|
||||
let _ = writeln!(f, "tool_call body: {}...", &part[..end]);
|
||||
}
|
||||
let _ = writeln!(f, " unparsed text: {}", &full_text[..end]);
|
||||
}
|
||||
}
|
||||
if let Some(u) = usage {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue