From 316e6231c27728f4031f822287389c67e914739a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 8 Aug 2024 20:21:43 +0000 Subject: [PATCH 1/5] chore(internal): updates (#6) --- .stats.yml | 2 +- chat.go | 2 +- chatcompletion.go | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index ac652c9..cad2c64 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 68 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-4097c2f86beb3f3bb021775cd1dfa240e960caf842aeefc2e08da4dc0851ea79.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-97797a9363b9960b5f2fbdc84426a2b91e75533ecd409fe99e37c231180a4339.yml diff --git a/chat.go b/chat.go index e20be1e..d6e46a7 100644 --- a/chat.go +++ b/chat.go @@ -31,8 +31,8 @@ type ChatModel = string const ( ChatModelGPT4o ChatModel = "gpt-4o" - ChatModelGPT4o2024_08_06 ChatModel = "gpt-4o-2024-08-06" ChatModelGPT4o2024_05_13 ChatModel = "gpt-4o-2024-05-13" + ChatModelGPT4o2024_08_06 ChatModel = "gpt-4o-2024-08-06" ChatModelGPT4oMini ChatModel = "gpt-4o-mini" ChatModelGPT4oMini2024_07_18 ChatModel = "gpt-4o-mini-2024-07-18" ChatModelGPT4Turbo ChatModel = "gpt-4-turbo" diff --git a/chatcompletion.go b/chatcompletion.go index 664eae4..ed0b018 100644 --- a/chatcompletion.go +++ b/chatcompletion.go @@ -1472,6 +1472,11 @@ type ChatCompletionNewParams struct { // [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo) and // all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. // + // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured + // Outputs which guarantees the model will match your supplied JSON schema. Learn + // more in the + // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + // // Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the // message the model generates is valid JSON. // @@ -1610,6 +1615,11 @@ func (r ChatCompletionNewParamsFunction) MarshalJSON() (data []byte, err error) // [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo) and // all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. // +// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured +// Outputs which guarantees the model will match your supplied JSON schema. Learn +// more in the +// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). +// // Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the // message the model generates is valid JSON. // @@ -1639,6 +1649,11 @@ func (r ChatCompletionNewParamsResponseFormat) ImplementsChatCompletionNewParams // [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo) and // all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. // +// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured +// Outputs which guarantees the model will match your supplied JSON schema. Learn +// more in the +// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). +// // Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the // message the model generates is valid JSON. // From be41ac2ce87efacf17748cb9dd2d3b1b4a43180e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:33:08 +0000 Subject: [PATCH 2/5] chore(ci): codeowners file (#9) --- .github/CODEOWNERS | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..d58c845 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,4 @@ +# This file is used to automatically assign reviewers to PRs +# For more information see: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners + +* @openai/sdks-team From 00f9455692c52fb37544d3f657090b216667d8ec Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 17:44:00 +0000 Subject: [PATCH 3/5] chore(ci): bump prism mock server version (#10) --- scripts/mock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/mock b/scripts/mock index f586157..d2814ae 100755 --- a/scripts/mock +++ b/scripts/mock @@ -21,7 +21,7 @@ echo "==> Starting mock server with URL ${URL}" # Run prism mock on the given spec if [ "$1" == "--daemon" ]; then - npm exec --package=@stainless-api/prism-cli@5.8.4 -- prism mock "$URL" &> .prism.log & + npm exec --package=@stainless-api/prism-cli@5.8.5 -- prism mock "$URL" &> .prism.log & # Wait for server to come online echo -n "Waiting for server" @@ -37,5 +37,5 @@ if [ "$1" == "--daemon" ]; then echo else - npm exec --package=@stainless-api/prism-cli@5.8.4 -- prism mock "$URL" + npm exec --package=@stainless-api/prism-cli@5.8.5 -- prism mock "$URL" fi From 7c0847aa2ae15b4442ab0625d8a780ed684c275e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 20:00:01 +0000 Subject: [PATCH 4/5] fix: deserialization of struct unions that implement json.Unmarshaler (#11) --- internal/apijson/decoder.go | 4 ++- internal/apijson/json_test.go | 62 +++++++++++++++++++++++++++++++++++ internal/apijson/registry.go | 4 +++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/internal/apijson/decoder.go b/internal/apijson/decoder.go index e1b21b7..68b7ed6 100644 --- a/internal/apijson/decoder.go +++ b/internal/apijson/decoder.go @@ -143,7 +143,9 @@ func (d *decoderBuilder) newTypeDecoder(t reflect.Type) decoderFunc { return unmarshalerDecoder } if !d.root && reflect.PointerTo(t).Implements(reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()) { - return indirectUnmarshalerDecoder + if _, ok := unionVariants[t]; !ok { + return indirectUnmarshalerDecoder + } } d.root = false diff --git a/internal/apijson/json_test.go b/internal/apijson/json_test.go index 72bc4c2..85cd2b5 100644 --- a/internal/apijson/json_test.go +++ b/internal/apijson/json_test.go @@ -261,6 +261,59 @@ func init() { ) } +type MarshallingUnionStruct struct { + Union MarshallingUnion +} + +func (r *MarshallingUnionStruct) UnmarshalJSON(data []byte) (err error) { + *r = MarshallingUnionStruct{} + err = UnmarshalRoot(data, &r.Union) + return +} + +func (r MarshallingUnionStruct) MarshalJSON() (data []byte, err error) { + return MarshalRoot(r.Union) +} + +type MarshallingUnion interface { + marshallingUnion() +} + +type MarshallingUnionA struct { + Boo string `json:"boo"` +} + +func (MarshallingUnionA) marshallingUnion() {} + +func (r *MarshallingUnionA) UnmarshalJSON(data []byte) (err error) { + return UnmarshalRoot(data, r) +} + +type MarshallingUnionB struct { + Foo string `json:"foo"` +} + +func (MarshallingUnionB) marshallingUnion() {} + +func (r *MarshallingUnionB) UnmarshalJSON(data []byte) (err error) { + return UnmarshalRoot(data, r) +} + +func init() { + RegisterUnion( + reflect.TypeOf((*MarshallingUnion)(nil)).Elem(), + "", + UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(MarshallingUnionA{}), + }, + UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(MarshallingUnionB{}), + }, + ) +} + var tests = map[string]struct { buf string val interface{} @@ -489,6 +542,15 @@ var tests = map[string]struct { ComplexUnionStruct{Union: ComplexUnionTypeB{Baz: 12, Type: TypeB("b")}}, }, + "marshalling_union_a": { + `{"boo":"hello"}`, + MarshallingUnionStruct{Union: MarshallingUnionA{Boo: "hello"}}, + }, + "marshalling_union_b": { + `{"foo":"hi"}`, + MarshallingUnionStruct{Union: MarshallingUnionB{Foo: "hi"}}, + }, + "unmarshal": { `{"foo":"hello"}`, &UnmarshalStruct{Foo: "hello", prop: true}, diff --git a/internal/apijson/registry.go b/internal/apijson/registry.go index fcc518b..2ea00ae 100644 --- a/internal/apijson/registry.go +++ b/internal/apijson/registry.go @@ -13,6 +13,7 @@ type UnionVariant struct { } var unionRegistry = map[reflect.Type]unionEntry{} +var unionVariants = map[reflect.Type]interface{}{} type unionEntry struct { discriminatorKey string @@ -24,4 +25,7 @@ func RegisterUnion(typ reflect.Type, discriminator string, variants ...UnionVari discriminatorKey: discriminator, variants: variants, } + for _, variant := range variants { + unionVariants[variant.Type] = typ + } } From b34a9860a764e4a58eb1dd949f91ee429ef085df Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 10 Aug 2024 05:02:21 +0000 Subject: [PATCH 5/5] release: 0.1.0-alpha.2 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 15 +++++++++++++++ README.md | 2 +- internal/version.go | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index ba6c348..f14b480 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.1" + ".": "0.1.0-alpha.2" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e5b7a13..1a38607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 0.1.0-alpha.2 (2024-08-10) + +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) + +### Bug Fixes + +* 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)) + + +### Chores + +* **ci:** bump prism mock server version ([#10](https://github.com/openai/openai-go/issues/10)) ([00f9455](https://github.com/openai/openai-go/commit/00f9455692c52fb37544d3f657090b216667d8ec)) +* **ci:** codeowners file ([#9](https://github.com/openai/openai-go/issues/9)) ([be41ac2](https://github.com/openai/openai-go/commit/be41ac2ce87efacf17748cb9dd2d3b1b4a43180e)) +* **internal:** updates ([#6](https://github.com/openai/openai-go/issues/6)) ([316e623](https://github.com/openai/openai-go/commit/316e6231c27728f4031f822287389c67e914739a)) + ## 0.1.0-alpha.1 (2024-08-06) 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) diff --git a/README.md b/README.md index d3ca018..a6fbf9d 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Or to pin the version: ```sh -go get -u 'github.com/openai/openai-go@v0.1.0-alpha.1' +go get -u 'github.com/openai/openai-go@v0.1.0-alpha.2' ``` diff --git a/internal/version.go b/internal/version.go index 5ed22d7..d6f40b3 100644 --- a/internal/version.go +++ b/internal/version.go @@ -2,4 +2,4 @@ package internal -const PackageVersion = "0.1.0-alpha.1" // x-release-please-version +const PackageVersion = "0.1.0-alpha.2" // x-release-please-version