Skip to content

Commit 88cff57

Browse files
authored
Merge pull request #7 from openai/release-please--branches--main--changes--next
release: 0.1.0-alpha.2
2 parents 8c9d560 + ac01e45 commit 88cff57

File tree

12 files changed

+110
-8
lines changed

12 files changed

+110
-8
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file is used to automatically assign reviewers to PRs
2+
# For more information see: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
3+
4+
* @openai/sdks-team

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.1.0-alpha.1"
2+
".": "0.1.0-alpha.2"
33
}

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 68
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-4097c2f86beb3f3bb021775cd1dfa240e960caf842aeefc2e08da4dc0851ea79.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-97797a9363b9960b5f2fbdc84426a2b91e75533ecd409fe99e37c231180a4339.yml

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## 0.1.0-alpha.2 (2024-08-10)
4+
5+
Full Changelog: [v0.1.0-alpha.1...v0.1.0-alpha.2](https://github.com/openai/openai-go/compare/v0.1.0-alpha.1...v0.1.0-alpha.2)
6+
7+
### Bug Fixes
8+
9+
* deserialization of struct unions that implement json.Unmarshaler ([#11](https://github.com/openai/openai-go/issues/11)) ([7c0847a](https://github.com/openai/openai-go/commit/7c0847aa2ae15b4442ab0625d8a780ed684c275e))
10+
11+
12+
### Chores
13+
14+
* **ci:** bump prism mock server version ([#10](https://github.com/openai/openai-go/issues/10)) ([00f9455](https://github.com/openai/openai-go/commit/00f9455692c52fb37544d3f657090b216667d8ec))
15+
* **ci:** codeowners file ([#9](https://github.com/openai/openai-go/issues/9)) ([be41ac2](https://github.com/openai/openai-go/commit/be41ac2ce87efacf17748cb9dd2d3b1b4a43180e))
16+
* **internal:** updates ([#6](https://github.com/openai/openai-go/issues/6)) ([316e623](https://github.com/openai/openai-go/commit/316e6231c27728f4031f822287389c67e914739a))
17+
318
## 0.1.0-alpha.1 (2024-08-06)
419

520
Full Changelog: [v0.0.1-alpha.0...v0.1.0-alpha.1](https://github.com/openai/openai-go/compare/v0.0.1-alpha.0...v0.1.0-alpha.1)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Or to pin the version:
2222
<!-- x-release-please-start-version -->
2323

2424
```sh
25-
go get -u 'github.com/openai/[email protected].1'
25+
go get -u 'github.com/openai/[email protected].2'
2626
```
2727

2828
<!-- x-release-please-end -->

chat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type ChatModel = string
3131

3232
const (
3333
ChatModelGPT4o ChatModel = "gpt-4o"
34-
ChatModelGPT4o2024_08_06 ChatModel = "gpt-4o-2024-08-06"
3534
ChatModelGPT4o2024_05_13 ChatModel = "gpt-4o-2024-05-13"
35+
ChatModelGPT4o2024_08_06 ChatModel = "gpt-4o-2024-08-06"
3636
ChatModelGPT4oMini ChatModel = "gpt-4o-mini"
3737
ChatModelGPT4oMini2024_07_18 ChatModel = "gpt-4o-mini-2024-07-18"
3838
ChatModelGPT4Turbo ChatModel = "gpt-4-turbo"

chatcompletion.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,11 @@ type ChatCompletionNewParams struct {
14721472
// [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo) and
14731473
// all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`.
14741474
//
1475+
// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
1476+
// Outputs which guarantees the model will match your supplied JSON schema. Learn
1477+
// more in the
1478+
// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
1479+
//
14751480
// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
14761481
// message the model generates is valid JSON.
14771482
//
@@ -1610,6 +1615,11 @@ func (r ChatCompletionNewParamsFunction) MarshalJSON() (data []byte, err error)
16101615
// [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo) and
16111616
// all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`.
16121617
//
1618+
// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
1619+
// Outputs which guarantees the model will match your supplied JSON schema. Learn
1620+
// more in the
1621+
// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
1622+
//
16131623
// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
16141624
// message the model generates is valid JSON.
16151625
//
@@ -1639,6 +1649,11 @@ func (r ChatCompletionNewParamsResponseFormat) ImplementsChatCompletionNewParams
16391649
// [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo) and
16401650
// all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`.
16411651
//
1652+
// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
1653+
// Outputs which guarantees the model will match your supplied JSON schema. Learn
1654+
// more in the
1655+
// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
1656+
//
16421657
// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
16431658
// message the model generates is valid JSON.
16441659
//

internal/apijson/decoder.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ func (d *decoderBuilder) newTypeDecoder(t reflect.Type) decoderFunc {
143143
return unmarshalerDecoder
144144
}
145145
if !d.root && reflect.PointerTo(t).Implements(reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()) {
146-
return indirectUnmarshalerDecoder
146+
if _, ok := unionVariants[t]; !ok {
147+
return indirectUnmarshalerDecoder
148+
}
147149
}
148150
d.root = false
149151

internal/apijson/json_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,59 @@ func init() {
261261
)
262262
}
263263

264+
type MarshallingUnionStruct struct {
265+
Union MarshallingUnion
266+
}
267+
268+
func (r *MarshallingUnionStruct) UnmarshalJSON(data []byte) (err error) {
269+
*r = MarshallingUnionStruct{}
270+
err = UnmarshalRoot(data, &r.Union)
271+
return
272+
}
273+
274+
func (r MarshallingUnionStruct) MarshalJSON() (data []byte, err error) {
275+
return MarshalRoot(r.Union)
276+
}
277+
278+
type MarshallingUnion interface {
279+
marshallingUnion()
280+
}
281+
282+
type MarshallingUnionA struct {
283+
Boo string `json:"boo"`
284+
}
285+
286+
func (MarshallingUnionA) marshallingUnion() {}
287+
288+
func (r *MarshallingUnionA) UnmarshalJSON(data []byte) (err error) {
289+
return UnmarshalRoot(data, r)
290+
}
291+
292+
type MarshallingUnionB struct {
293+
Foo string `json:"foo"`
294+
}
295+
296+
func (MarshallingUnionB) marshallingUnion() {}
297+
298+
func (r *MarshallingUnionB) UnmarshalJSON(data []byte) (err error) {
299+
return UnmarshalRoot(data, r)
300+
}
301+
302+
func init() {
303+
RegisterUnion(
304+
reflect.TypeOf((*MarshallingUnion)(nil)).Elem(),
305+
"",
306+
UnionVariant{
307+
TypeFilter: gjson.JSON,
308+
Type: reflect.TypeOf(MarshallingUnionA{}),
309+
},
310+
UnionVariant{
311+
TypeFilter: gjson.JSON,
312+
Type: reflect.TypeOf(MarshallingUnionB{}),
313+
},
314+
)
315+
}
316+
264317
var tests = map[string]struct {
265318
buf string
266319
val interface{}
@@ -489,6 +542,15 @@ var tests = map[string]struct {
489542
ComplexUnionStruct{Union: ComplexUnionTypeB{Baz: 12, Type: TypeB("b")}},
490543
},
491544

545+
"marshalling_union_a": {
546+
`{"boo":"hello"}`,
547+
MarshallingUnionStruct{Union: MarshallingUnionA{Boo: "hello"}},
548+
},
549+
"marshalling_union_b": {
550+
`{"foo":"hi"}`,
551+
MarshallingUnionStruct{Union: MarshallingUnionB{Foo: "hi"}},
552+
},
553+
492554
"unmarshal": {
493555
`{"foo":"hello"}`,
494556
&UnmarshalStruct{Foo: "hello", prop: true},

internal/apijson/registry.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type UnionVariant struct {
1313
}
1414

1515
var unionRegistry = map[reflect.Type]unionEntry{}
16+
var unionVariants = map[reflect.Type]interface{}{}
1617

1718
type unionEntry struct {
1819
discriminatorKey string
@@ -24,4 +25,7 @@ func RegisterUnion(typ reflect.Type, discriminator string, variants ...UnionVari
2425
discriminatorKey: discriminator,
2526
variants: variants,
2627
}
28+
for _, variant := range variants {
29+
unionVariants[variant.Type] = typ
30+
}
2731
}

0 commit comments

Comments
 (0)