From 89651e4ebb80179b2fcc92d3c573679683a39201 Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Wed, 18 Sep 2024 16:26:14 +0000 Subject: [PATCH 1/2] feat: fix(streaming): correctly accumulate tool calls and roles (#55) --- streamaccumulator.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/streamaccumulator.go b/streamaccumulator.go index 5fb45059..3b9f2077 100644 --- a/streamaccumulator.go +++ b/streamaccumulator.go @@ -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 @@ -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 } From a0ae0171cb638eded2de90c2781dc1eabcd74f4c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:26:37 +0000 Subject: [PATCH 2/2] release: 0.1.0-alpha.19 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ README.md | 2 +- internal/version.go | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 3cf71e62..b386befd 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.18" + ".": "0.1.0-alpha.19" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 48fb3794..a3fde605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index a928709a..1816bb51 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Or to pin the 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' ``` diff --git a/internal/version.go b/internal/version.go index 53d10d96..296d72bc 100644 --- a/internal/version.go +++ b/internal/version.go @@ -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