Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.18"
".": "0.1.0-alpha.19"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.1.0-alpha.19 (2024-09-18)

Full Changelog: [v0.1.0-alpha.18...v0.1.0-alpha.19](https://github.com/openai/openai-go/compare/v0.1.0-alpha.18...v0.1.0-alpha.19)

### Features

* fix(streaming): correctly accumulate tool calls and roles ([#55](https://github.com/openai/openai-go/issues/55)) ([89651e4](https://github.com/openai/openai-go/commit/89651e4ebb80179b2fcc92d3c573679683a39201))

## 0.1.0-alpha.18 (2024-09-16)

Full Changelog: [v0.1.0-alpha.17...v0.1.0-alpha.18](https://github.com/openai/openai-go/compare/v0.1.0-alpha.17...v0.1.0-alpha.18)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Or to pin the version:
<!-- x-release-please-start-version -->

```sh
go get -u 'github.com/openai/openai-go@v0.1.0-alpha.18'
go get -u 'github.com/openai/openai-go@v0.1.0-alpha.19'
```

<!-- x-release-please-end -->
Expand Down
2 changes: 1 addition & 1 deletion internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

package internal

const PackageVersion = "0.1.0-alpha.18" // x-release-please-version
const PackageVersion = "0.1.0-alpha.19" // x-release-please-version
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)
}
tool.Function.Name += deltaTool.Function.Name
tool.Function.Arguments += deltaTool.Function.Arguments
}
Expand Down