fix logging assistant messages
This commit is contained in:
parent
dcf9dadb1c
commit
98a1ae74d7
2 changed files with 14 additions and 4 deletions
|
|
@ -309,14 +309,22 @@ impl Agent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finalize the streaming entry with the complete response message.
|
/// Finalize the streaming entry with the complete response message.
|
||||||
/// Finds the unstamped assistant entry and updates it in place.
|
/// Finds the unstamped assistant entry, updates it in place, and logs it.
|
||||||
fn finalize_streaming(&mut self, msg: Message) {
|
fn finalize_streaming(&mut self, msg: Message) {
|
||||||
if let Some(m) = self.streaming_entry() {
|
if let Some(m) = self.streaming_entry() {
|
||||||
*m = msg;
|
*m = msg.clone();
|
||||||
m.stamp();
|
m.stamp();
|
||||||
} else {
|
} else {
|
||||||
// No streaming entry found — push as new
|
// No streaming entry found — push as new (this logs via push_message)
|
||||||
self.push_message(msg);
|
self.push_message(msg.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log the finalized entry
|
||||||
|
if let Some(ref log) = self.conversation_log {
|
||||||
|
let entry = ConversationEntry::Message(msg);
|
||||||
|
if let Err(e) = log.append(&entry) {
|
||||||
|
eprintln!("warning: failed to log finalized entry: {:#}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.changed.notify_one();
|
self.changed.notify_one();
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@ impl ConversationLog {
|
||||||
.context("serializing entry for log")?;
|
.context("serializing entry for log")?;
|
||||||
writeln!(file, "{}", line)
|
writeln!(file, "{}", line)
|
||||||
.context("writing to conversation log")?;
|
.context("writing to conversation log")?;
|
||||||
|
file.sync_all()
|
||||||
|
.context("syncing conversation log")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue