feat: accumulate assistant response chunks and push to messages history for session tracking
This commit is contained in:
+7
-2
@@ -47,13 +47,14 @@ fn main() {
|
||||
Ok(data) => {
|
||||
let raw_text = String::from_utf8_lossy(&data);
|
||||
let mut lines = raw_text.lines();
|
||||
let mut assistant_response = String::new();
|
||||
while let Some(line) = lines.next() {
|
||||
match serde_json::from_str::<serde_json::Value>(line) {
|
||||
Ok(json_response) => {
|
||||
if let Some(message) = json_response.get("message") {
|
||||
if let Some(content) = message.get("content") {
|
||||
if let Some(s) = content.as_str() {
|
||||
print!("{}", s);
|
||||
assistant_response.push_str(s);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -65,6 +66,10 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
messages.push(json!({
|
||||
"role": "assistant",
|
||||
"content": assistant_response
|
||||
}));
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error reading response: {:?}", e);
|
||||
@@ -78,4 +83,4 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user