Skip to content

Commit

Permalink
release: 0.1.0-alpha.54 (#212)
Browse files Browse the repository at this point in the history
* chore: add UnionUnmarshaler for responses that are interfaces (#211)

* fix(streaming): correctly decode assistant events

* release: 0.1.0-alpha.54

---------

Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
Co-authored-by: Robert Craigie <[email protected]>
  • Loading branch information
stainless-app[bot] and RobertCraigie authored Feb 5, 2025
1 parent 7daddef commit 30d43c0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
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.53"
".": "0.1.0-alpha.54"
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.1.0-alpha.54 (2025-02-05)

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

### Bug Fixes

* **streaming:** correctly decode assistant events ([38ded46](https://github.com/openai/openai-go/commit/38ded4694480071a768eb4d2790ba4552e001506))


### Chores

* add UnionUnmarshaler for responses that are interfaces ([#211](https://github.com/openai/openai-go/issues/211)) ([185d848](https://github.com/openai/openai-go/commit/185d848cd3e9efb48f7468acc06a8b78f3a7b785))

## 0.1.0-alpha.53 (2025-02-05)

Full Changelog: [v0.1.0-alpha.52...v0.1.0-alpha.53](https://github.com/openai/openai-go/compare/v0.1.0-alpha.52...v0.1.0-alpha.53)
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/[email protected].53'
go get -u 'github.com/openai/[email protected].54'
```

<!-- x-release-please-end -->
Expand Down
10 changes: 10 additions & 0 deletions internal/apijson/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ func RegisterUnion(typ reflect.Type, discriminator string, variants ...UnionVari
unionVariants[variant.Type] = typ
}
}

// Useful to wrap a union type to force it to use [apijson.UnmarshalJSON] since you cannot define an
// UnmarshalJSON function on the interface itself.
type UnionUnmarshaler[T any] struct {
Value T
}

func (c *UnionUnmarshaler[T]) UnmarshalJSON(buf []byte) error {
return UnmarshalRoot(buf, &c.Value)
}
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.53" // x-release-please-version
const PackageVersion = "0.1.0-alpha.54" // x-release-please-version
31 changes: 22 additions & 9 deletions packages/ssestream/ssestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,29 @@ func (s *Stream[T]) Next() bool {
continue
}

ep := gjson.GetBytes(s.decoder.Event().Data, "error")
if ep.Exists() {
s.err = fmt.Errorf("received error while streaming: %s", ep.String())
return false
}
s.err = json.Unmarshal(s.decoder.Event().Data, &s.cur)
if s.err != nil {
return false
if s.decoder.Event().Type == "" {
ep := gjson.GetBytes(s.decoder.Event().Data, "error")
if ep.Exists() {
s.err = fmt.Errorf("received error while streaming: %s", ep.String())
return false
}
s.err = json.Unmarshal(s.decoder.Event().Data, &s.cur)
if s.err != nil {
return false
}
return true
} else {
ep := gjson.GetBytes(s.decoder.Event().Data, "error")
if ep.Exists() {
s.err = fmt.Errorf("received error while streaming: %s", ep.String())
return false
}
s.err = json.Unmarshal([]byte(fmt.Sprintf(`{ "event": %q, "data": %s }`, s.decoder.Event().Type, s.decoder.Event().Data)), &s.cur)
if s.err != nil {
return false
}
return true
}
return true
}

return false
Expand Down

0 comments on commit 30d43c0

Please sign in to comment.