fix: field wasn't renamed

This commit is contained in:
yavens 2025-04-15 09:18:28 -04:00
parent 9689693468
commit bd4f5f27da
1 changed files with 6 additions and 8 deletions

View File

@ -91,21 +91,19 @@ impl<R: Clone + Unpin> Stream for StreamingCompletionResponse<R> {
Poll::Ready(None) => {
// This is run at the end of the inner stream to collect all tokens into
// a single unified `Message`.
let mut content = vec![];
let mut choice = vec![];
stream.tool_calls.iter().for_each(|tc| {
content.push(AssistantContent::ToolCall(tc.clone()));
choice.push(AssistantContent::ToolCall(tc.clone()));
});
// This is required to ensure there's always at least one item in the content
if content.is_empty() || !stream.text.is_empty() {
content.insert(0, AssistantContent::text(stream.text.clone()));
if choice.is_empty() || !stream.text.is_empty() {
choice.insert(0, AssistantContent::text(stream.text.clone()));
}
stream.message = Message::Assistant {
content: OneOrMany::many(content)
.expect("There should be at least one assistant message"),
};
stream.choice = OneOrMany::many(choice)
.expect("There should be at least one assistant message");
Poll::Ready(None)
}