Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions streamaccumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func (cc *ChatCompletion) accumulateDelta(chunk ChatCompletionChunk) bool {
choice.Index = delta.Index
choice.FinishReason = ChatCompletionChoicesFinishReason(delta.FinishReason)

if delta.Delta.Role != "" {
choice.Message.Role = ChatCompletionMessageRole(delta.Delta.Role)
}

choice.Message.Content += delta.Delta.Content
choice.Message.Refusal += delta.Delta.Refusal

Expand All @@ -119,8 +123,12 @@ func (cc *ChatCompletion) accumulateDelta(chunk ChatCompletionChunk) bool {
choice.Message.ToolCalls = expandToFit(choice.Message.ToolCalls, int(deltaTool.Index))
tool := &choice.Message.ToolCalls[deltaTool.Index]

tool.ID = deltaTool.ID
tool.Type = ChatCompletionMessageToolCallType(deltaTool.Type)
if deltaTool.ID != "" {
tool.ID = deltaTool.ID
}
if deltaTool.Type != "" {
tool.Type = ChatCompletionMessageToolCallType(deltaTool.Type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is slightly different to the node + python implementation, only for the Type param

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait what do you mean?

}
tool.Function.Name += deltaTool.Function.Name
tool.Function.Arguments += deltaTool.Function.Arguments
}
Expand Down