Skip to content

Commit b228103

Browse files
feat: simplify content union (#18)
1 parent 4af9109 commit b228103

13 files changed

+65
-178
lines changed

.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-97797a9363b9960b5f2fbdc84426a2b91e75533ecd409fe99e37c231180a4339.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-285bce7dcdae7eea5fe84a8d6e5af2c1473d65ea193109370fb2257851eef7eb.yml

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import (
4343

4444
"github.com/openai/openai-go"
4545
"github.com/openai/openai-go/option"
46-
"github.com/openai/openai-go/shared"
4746
)
4847

4948
func main() {
@@ -53,7 +52,7 @@ func main() {
5352
chatCompletion, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{
5453
Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{
5554
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
56-
Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("Say this is a test")),
55+
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
5756
}}),
5857
Model: openai.F(openai.ChatModelGPT4o),
5958
})
@@ -239,7 +238,7 @@ client.Chat.Completions.New(
239238
openai.ChatCompletionNewParams{
240239
Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{
241240
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
242-
Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("How can I list all files in a directory using Python?")),
241+
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
243242
}}),
244243
Model: openai.F(openai.ChatModelGPT4o),
245244
},
@@ -302,7 +301,7 @@ client.Chat.Completions.New(
302301
openai.ChatCompletionNewParams{
303302
Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{
304303
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
305-
Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("How can I get the name of the current day in Node.js?")),
304+
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
306305
}}),
307306
Model: openai.F(openai.ChatModelGPT4o),
308307
},

betathread.go

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,11 @@ func (r BetaThreadNewParams) MarshalJSON() (data []byte, err error) {
452452
}
453453

454454
type BetaThreadNewParamsMessage struct {
455-
// The text contents of the message.
456-
Content param.Field[BetaThreadNewParamsMessagesContentUnion] `json:"content,required"`
455+
// An array of content parts with a defined type, each can be of type `text` or
456+
// images can be passed with `image_url` or `image_file`. Image types are only
457+
// supported on
458+
// [Vision-compatible models](https://platform.openai.com/docs/models/overview).
459+
Content param.Field[[]MessageContentPartParamUnion] `json:"content,required"`
457460
// The role of the entity that is creating the message. Allowed values include:
458461
//
459462
// - `user`: Indicates the message is sent by an actual user and should be used in
@@ -474,19 +477,6 @@ func (r BetaThreadNewParamsMessage) MarshalJSON() (data []byte, err error) {
474477
return apijson.MarshalRoot(r)
475478
}
476479

477-
// The text contents of the message.
478-
//
479-
// Satisfied by [shared.UnionString],
480-
// [BetaThreadNewParamsMessagesContentArrayOfContentParts].
481-
type BetaThreadNewParamsMessagesContentUnion interface {
482-
ImplementsBetaThreadNewParamsMessagesContentUnion()
483-
}
484-
485-
type BetaThreadNewParamsMessagesContentArrayOfContentParts []MessageContentPartParamUnion
486-
487-
func (r BetaThreadNewParamsMessagesContentArrayOfContentParts) ImplementsBetaThreadNewParamsMessagesContentUnion() {
488-
}
489-
490480
// The role of the entity that is creating the message. Allowed values include:
491481
//
492482
// - `user`: Indicates the message is sent by an actual user and should be used in
@@ -900,8 +890,11 @@ func (r BetaThreadNewAndRunParamsThread) MarshalJSON() (data []byte, err error)
900890
}
901891

902892
type BetaThreadNewAndRunParamsThreadMessage struct {
903-
// The text contents of the message.
904-
Content param.Field[BetaThreadNewAndRunParamsThreadMessagesContentUnion] `json:"content,required"`
893+
// An array of content parts with a defined type, each can be of type `text` or
894+
// images can be passed with `image_url` or `image_file`. Image types are only
895+
// supported on
896+
// [Vision-compatible models](https://platform.openai.com/docs/models/overview).
897+
Content param.Field[[]MessageContentPartParamUnion] `json:"content,required"`
905898
// The role of the entity that is creating the message. Allowed values include:
906899
//
907900
// - `user`: Indicates the message is sent by an actual user and should be used in
@@ -922,19 +915,6 @@ func (r BetaThreadNewAndRunParamsThreadMessage) MarshalJSON() (data []byte, err
922915
return apijson.MarshalRoot(r)
923916
}
924917

925-
// The text contents of the message.
926-
//
927-
// Satisfied by [shared.UnionString],
928-
// [BetaThreadNewAndRunParamsThreadMessagesContentArrayOfContentParts].
929-
type BetaThreadNewAndRunParamsThreadMessagesContentUnion interface {
930-
ImplementsBetaThreadNewAndRunParamsThreadMessagesContentUnion()
931-
}
932-
933-
type BetaThreadNewAndRunParamsThreadMessagesContentArrayOfContentParts []MessageContentPartParamUnion
934-
935-
func (r BetaThreadNewAndRunParamsThreadMessagesContentArrayOfContentParts) ImplementsBetaThreadNewAndRunParamsThreadMessagesContentUnion() {
936-
}
937-
938918
// The role of the entity that is creating the message. Allowed values include:
939919
//
940920
// - `user`: Indicates the message is sent by an actual user and should be used in

betathread_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/openai/openai-go"
1212
"github.com/openai/openai-go/internal/testutil"
1313
"github.com/openai/openai-go/option"
14-
"github.com/openai/openai-go/shared"
1514
)
1615

1716
func TestBetaThreadNewWithOptionalParams(t *testing.T) {
@@ -28,7 +27,7 @@ func TestBetaThreadNewWithOptionalParams(t *testing.T) {
2827
)
2928
_, err := client.Beta.Threads.New(context.TODO(), openai.BetaThreadNewParams{
3029
Messages: openai.F([]openai.BetaThreadNewParamsMessage{{
31-
Content: openai.F[openai.BetaThreadNewParamsMessagesContentUnion](shared.UnionString("string")),
30+
Content: openai.F([]openai.MessageContentPartParamUnion{openai.ImageFileContentBlockParam{ImageFile: openai.F(openai.ImageFileParam{FileID: openai.F("file_id"), Detail: openai.F(openai.ImageFileDetailAuto)}), Type: openai.F(openai.ImageFileContentBlockTypeImageFile)}}),
3231
Role: openai.F(openai.BetaThreadNewParamsMessagesRoleUser),
3332
Attachments: openai.F([]openai.BetaThreadNewParamsMessagesAttachment{{
3433
FileID: openai.F("file_id"),
@@ -60,7 +59,7 @@ func TestBetaThreadNewWithOptionalParams(t *testing.T) {
6059
}}),
6160
Metadata: openai.F[any](map[string]interface{}{}),
6261
}, {
63-
Content: openai.F[openai.BetaThreadNewParamsMessagesContentUnion](shared.UnionString("string")),
62+
Content: openai.F([]openai.MessageContentPartParamUnion{openai.ImageFileContentBlockParam{ImageFile: openai.F(openai.ImageFileParam{FileID: openai.F("file_id"), Detail: openai.F(openai.ImageFileDetailAuto)}), Type: openai.F(openai.ImageFileContentBlockTypeImageFile)}}),
6463
Role: openai.F(openai.BetaThreadNewParamsMessagesRoleUser),
6564
Attachments: openai.F([]openai.BetaThreadNewParamsMessagesAttachment{{
6665
FileID: openai.F("file_id"),
@@ -92,7 +91,7 @@ func TestBetaThreadNewWithOptionalParams(t *testing.T) {
9291
}}),
9392
Metadata: openai.F[any](map[string]interface{}{}),
9493
}, {
95-
Content: openai.F[openai.BetaThreadNewParamsMessagesContentUnion](shared.UnionString("string")),
94+
Content: openai.F([]openai.MessageContentPartParamUnion{openai.ImageFileContentBlockParam{ImageFile: openai.F(openai.ImageFileParam{FileID: openai.F("file_id"), Detail: openai.F(openai.ImageFileDetailAuto)}), Type: openai.F(openai.ImageFileContentBlockTypeImageFile)}}),
9695
Role: openai.F(openai.BetaThreadNewParamsMessagesRoleUser),
9796
Attachments: openai.F([]openai.BetaThreadNewParamsMessagesAttachment{{
9897
FileID: openai.F("file_id"),
@@ -253,7 +252,7 @@ func TestBetaThreadNewAndRunWithOptionalParams(t *testing.T) {
253252
Temperature: openai.F(1.000000),
254253
Thread: openai.F(openai.BetaThreadNewAndRunParamsThread{
255254
Messages: openai.F([]openai.BetaThreadNewAndRunParamsThreadMessage{{
256-
Content: openai.F[openai.BetaThreadNewAndRunParamsThreadMessagesContentUnion](shared.UnionString("string")),
255+
Content: openai.F([]openai.MessageContentPartParamUnion{openai.ImageFileContentBlockParam{ImageFile: openai.F(openai.ImageFileParam{FileID: openai.F("file_id"), Detail: openai.F(openai.ImageFileDetailAuto)}), Type: openai.F(openai.ImageFileContentBlockTypeImageFile)}}),
257256
Role: openai.F(openai.BetaThreadNewAndRunParamsThreadMessagesRoleUser),
258257
Attachments: openai.F([]openai.BetaThreadNewAndRunParamsThreadMessagesAttachment{{
259258
FileID: openai.F("file_id"),
@@ -285,7 +284,7 @@ func TestBetaThreadNewAndRunWithOptionalParams(t *testing.T) {
285284
}}),
286285
Metadata: openai.F[any](map[string]interface{}{}),
287286
}, {
288-
Content: openai.F[openai.BetaThreadNewAndRunParamsThreadMessagesContentUnion](shared.UnionString("string")),
287+
Content: openai.F([]openai.MessageContentPartParamUnion{openai.ImageFileContentBlockParam{ImageFile: openai.F(openai.ImageFileParam{FileID: openai.F("file_id"), Detail: openai.F(openai.ImageFileDetailAuto)}), Type: openai.F(openai.ImageFileContentBlockTypeImageFile)}}),
289288
Role: openai.F(openai.BetaThreadNewAndRunParamsThreadMessagesRoleUser),
290289
Attachments: openai.F([]openai.BetaThreadNewAndRunParamsThreadMessagesAttachment{{
291290
FileID: openai.F("file_id"),
@@ -317,7 +316,7 @@ func TestBetaThreadNewAndRunWithOptionalParams(t *testing.T) {
317316
}}),
318317
Metadata: openai.F[any](map[string]interface{}{}),
319318
}, {
320-
Content: openai.F[openai.BetaThreadNewAndRunParamsThreadMessagesContentUnion](shared.UnionString("string")),
319+
Content: openai.F([]openai.MessageContentPartParamUnion{openai.ImageFileContentBlockParam{ImageFile: openai.F(openai.ImageFileParam{FileID: openai.F("file_id"), Detail: openai.F(openai.ImageFileDetailAuto)}), Type: openai.F(openai.ImageFileContentBlockTypeImageFile)}}),
321320
Role: openai.F(openai.BetaThreadNewAndRunParamsThreadMessagesRoleUser),
322321
Attachments: openai.F([]openai.BetaThreadNewAndRunParamsThreadMessagesAttachment{{
323322
FileID: openai.F("file_id"),

betathreadmessage.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,8 +1945,11 @@ func (r TextDeltaBlockType) IsKnown() bool {
19451945
}
19461946

19471947
type BetaThreadMessageNewParams struct {
1948-
// The text contents of the message.
1949-
Content param.Field[BetaThreadMessageNewParamsContentUnion] `json:"content,required"`
1948+
// An array of content parts with a defined type, each can be of type `text` or
1949+
// images can be passed with `image_url` or `image_file`. Image types are only
1950+
// supported on
1951+
// [Vision-compatible models](https://platform.openai.com/docs/models/overview).
1952+
Content param.Field[[]MessageContentPartParamUnion] `json:"content,required"`
19501953
// The role of the entity that is creating the message. Allowed values include:
19511954
//
19521955
// - `user`: Indicates the message is sent by an actual user and should be used in
@@ -1967,19 +1970,6 @@ func (r BetaThreadMessageNewParams) MarshalJSON() (data []byte, err error) {
19671970
return apijson.MarshalRoot(r)
19681971
}
19691972

1970-
// The text contents of the message.
1971-
//
1972-
// Satisfied by [shared.UnionString],
1973-
// [BetaThreadMessageNewParamsContentArrayOfContentParts].
1974-
type BetaThreadMessageNewParamsContentUnion interface {
1975-
ImplementsBetaThreadMessageNewParamsContentUnion()
1976-
}
1977-
1978-
type BetaThreadMessageNewParamsContentArrayOfContentParts []MessageContentPartParamUnion
1979-
1980-
func (r BetaThreadMessageNewParamsContentArrayOfContentParts) ImplementsBetaThreadMessageNewParamsContentUnion() {
1981-
}
1982-
19831973
// The role of the entity that is creating the message. Allowed values include:
19841974
//
19851975
// - `user`: Indicates the message is sent by an actual user and should be used in

betathreadmessage_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/openai/openai-go"
1212
"github.com/openai/openai-go/internal/testutil"
1313
"github.com/openai/openai-go/option"
14-
"github.com/openai/openai-go/shared"
1514
)
1615

1716
func TestBetaThreadMessageNewWithOptionalParams(t *testing.T) {
@@ -30,7 +29,7 @@ func TestBetaThreadMessageNewWithOptionalParams(t *testing.T) {
3029
context.TODO(),
3130
"thread_id",
3231
openai.BetaThreadMessageNewParams{
33-
Content: openai.F[openai.BetaThreadMessageNewParamsContentUnion](shared.UnionString("string")),
32+
Content: openai.F([]openai.MessageContentPartParamUnion{openai.ImageFileContentBlockParam{ImageFile: openai.F(openai.ImageFileParam{FileID: openai.F("file_id"), Detail: openai.F(openai.ImageFileDetailAuto)}), Type: openai.F(openai.ImageFileContentBlockTypeImageFile)}}),
3433
Role: openai.F(openai.BetaThreadMessageNewParamsRoleUser),
3534
Attachments: openai.F([]openai.BetaThreadMessageNewParamsAttachment{{
3635
FileID: openai.F("file_id"),

betathreadrun.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,11 @@ func (r BetaThreadRunNewParams) MarshalJSON() (data []byte, err error) {
727727
}
728728

729729
type BetaThreadRunNewParamsAdditionalMessage struct {
730-
// The text contents of the message.
731-
Content param.Field[BetaThreadRunNewParamsAdditionalMessagesContentUnion] `json:"content,required"`
730+
// An array of content parts with a defined type, each can be of type `text` or
731+
// images can be passed with `image_url` or `image_file`. Image types are only
732+
// supported on
733+
// [Vision-compatible models](https://platform.openai.com/docs/models/overview).
734+
Content param.Field[[]MessageContentPartParamUnion] `json:"content,required"`
732735
// The role of the entity that is creating the message. Allowed values include:
733736
//
734737
// - `user`: Indicates the message is sent by an actual user and should be used in
@@ -749,19 +752,6 @@ func (r BetaThreadRunNewParamsAdditionalMessage) MarshalJSON() (data []byte, err
749752
return apijson.MarshalRoot(r)
750753
}
751754

752-
// The text contents of the message.
753-
//
754-
// Satisfied by [shared.UnionString],
755-
// [BetaThreadRunNewParamsAdditionalMessagesContentArrayOfContentParts].
756-
type BetaThreadRunNewParamsAdditionalMessagesContentUnion interface {
757-
ImplementsBetaThreadRunNewParamsAdditionalMessagesContentUnion()
758-
}
759-
760-
type BetaThreadRunNewParamsAdditionalMessagesContentArrayOfContentParts []MessageContentPartParamUnion
761-
762-
func (r BetaThreadRunNewParamsAdditionalMessagesContentArrayOfContentParts) ImplementsBetaThreadRunNewParamsAdditionalMessagesContentUnion() {
763-
}
764-
765755
// The role of the entity that is creating the message. Allowed values include:
766756
//
767757
// - `user`: Indicates the message is sent by an actual user and should be used in

betathreadrun_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/openai/openai-go"
1212
"github.com/openai/openai-go/internal/testutil"
1313
"github.com/openai/openai-go/option"
14-
"github.com/openai/openai-go/shared"
1514
)
1615

1716
func TestBetaThreadRunNewWithOptionalParams(t *testing.T) {
@@ -33,7 +32,7 @@ func TestBetaThreadRunNewWithOptionalParams(t *testing.T) {
3332
AssistantID: openai.F("assistant_id"),
3433
AdditionalInstructions: openai.F("additional_instructions"),
3534
AdditionalMessages: openai.F([]openai.BetaThreadRunNewParamsAdditionalMessage{{
36-
Content: openai.F[openai.BetaThreadRunNewParamsAdditionalMessagesContentUnion](shared.UnionString("string")),
35+
Content: openai.F([]openai.MessageContentPartParamUnion{openai.ImageFileContentBlockParam{ImageFile: openai.F(openai.ImageFileParam{FileID: openai.F("file_id"), Detail: openai.F(openai.ImageFileDetailAuto)}), Type: openai.F(openai.ImageFileContentBlockTypeImageFile)}}),
3736
Role: openai.F(openai.BetaThreadRunNewParamsAdditionalMessagesRoleUser),
3837
Attachments: openai.F([]openai.BetaThreadRunNewParamsAdditionalMessagesAttachment{{
3938
FileID: openai.F("file_id"),
@@ -65,7 +64,7 @@ func TestBetaThreadRunNewWithOptionalParams(t *testing.T) {
6564
}}),
6665
Metadata: openai.F[any](map[string]interface{}{}),
6766
}, {
68-
Content: openai.F[openai.BetaThreadRunNewParamsAdditionalMessagesContentUnion](shared.UnionString("string")),
67+
Content: openai.F([]openai.MessageContentPartParamUnion{openai.ImageFileContentBlockParam{ImageFile: openai.F(openai.ImageFileParam{FileID: openai.F("file_id"), Detail: openai.F(openai.ImageFileDetailAuto)}), Type: openai.F(openai.ImageFileContentBlockTypeImageFile)}}),
6968
Role: openai.F(openai.BetaThreadRunNewParamsAdditionalMessagesRoleUser),
7069
Attachments: openai.F([]openai.BetaThreadRunNewParamsAdditionalMessagesAttachment{{
7170
FileID: openai.F("file_id"),
@@ -97,7 +96,7 @@ func TestBetaThreadRunNewWithOptionalParams(t *testing.T) {
9796
}}),
9897
Metadata: openai.F[any](map[string]interface{}{}),
9998
}, {
100-
Content: openai.F[openai.BetaThreadRunNewParamsAdditionalMessagesContentUnion](shared.UnionString("string")),
99+
Content: openai.F([]openai.MessageContentPartParamUnion{openai.ImageFileContentBlockParam{ImageFile: openai.F(openai.ImageFileParam{FileID: openai.F("file_id"), Detail: openai.F(openai.ImageFileDetailAuto)}), Type: openai.F(openai.ImageFileContentBlockTypeImageFile)}}),
101100
Role: openai.F(openai.BetaThreadRunNewParamsAdditionalMessagesRoleUser),
102101
Attachments: openai.F([]openai.BetaThreadRunNewParamsAdditionalMessagesAttachment{{
103102
FileID: openai.F("file_id"),

0 commit comments

Comments
 (0)