diff --git a/.stats.yml b/.stats.yml index cad2c64c..2371b7b8 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-97797a9363b9960b5f2fbdc84426a2b91e75533ecd409fe99e37c231180a4339.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-285bce7dcdae7eea5fe84a8d6e5af2c1473d65ea193109370fb2257851eef7eb.yml diff --git a/README.md b/README.md index 87464506..ec3b16ad 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,6 @@ import ( "github.com/openai/openai-go" "github.com/openai/openai-go/option" - "github.com/openai/openai-go/shared" ) func main() { @@ -53,7 +52,7 @@ func main() { chatCompletion, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{ Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), - Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("Say this is a test")), + Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), Model: openai.F(openai.ChatModelGPT4o), }) @@ -239,7 +238,7 @@ client.Chat.Completions.New( openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{ Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), - Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("How can I list all files in a directory using Python?")), + Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), Model: openai.F(openai.ChatModelGPT4o), }, @@ -302,7 +301,7 @@ client.Chat.Completions.New( openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{ Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), - Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("How can I get the name of the current day in Node.js?")), + Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), Model: openai.F(openai.ChatModelGPT4o), }, diff --git a/betathread.go b/betathread.go index 1e2ef68b..7ed15c7b 100644 --- a/betathread.go +++ b/betathread.go @@ -452,8 +452,11 @@ func (r BetaThreadNewParams) MarshalJSON() (data []byte, err error) { } type BetaThreadNewParamsMessage struct { - // The text contents of the message. - Content param.Field[BetaThreadNewParamsMessagesContentUnion] `json:"content,required"` + // An array of content parts with a defined type, each can be of type `text` or + // images can be passed with `image_url` or `image_file`. Image types are only + // supported on + // [Vision-compatible models](https://platform.openai.com/docs/models/overview). + Content param.Field[[]MessageContentPartParamUnion] `json:"content,required"` // The role of the entity that is creating the message. Allowed values include: // // - `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) { return apijson.MarshalRoot(r) } -// The text contents of the message. -// -// Satisfied by [shared.UnionString], -// [BetaThreadNewParamsMessagesContentArrayOfContentParts]. -type BetaThreadNewParamsMessagesContentUnion interface { - ImplementsBetaThreadNewParamsMessagesContentUnion() -} - -type BetaThreadNewParamsMessagesContentArrayOfContentParts []MessageContentPartParamUnion - -func (r BetaThreadNewParamsMessagesContentArrayOfContentParts) ImplementsBetaThreadNewParamsMessagesContentUnion() { -} - // The role of the entity that is creating the message. Allowed values include: // // - `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) } type BetaThreadNewAndRunParamsThreadMessage struct { - // The text contents of the message. - Content param.Field[BetaThreadNewAndRunParamsThreadMessagesContentUnion] `json:"content,required"` + // An array of content parts with a defined type, each can be of type `text` or + // images can be passed with `image_url` or `image_file`. Image types are only + // supported on + // [Vision-compatible models](https://platform.openai.com/docs/models/overview). + Content param.Field[[]MessageContentPartParamUnion] `json:"content,required"` // The role of the entity that is creating the message. Allowed values include: // // - `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 return apijson.MarshalRoot(r) } -// The text contents of the message. -// -// Satisfied by [shared.UnionString], -// [BetaThreadNewAndRunParamsThreadMessagesContentArrayOfContentParts]. -type BetaThreadNewAndRunParamsThreadMessagesContentUnion interface { - ImplementsBetaThreadNewAndRunParamsThreadMessagesContentUnion() -} - -type BetaThreadNewAndRunParamsThreadMessagesContentArrayOfContentParts []MessageContentPartParamUnion - -func (r BetaThreadNewAndRunParamsThreadMessagesContentArrayOfContentParts) ImplementsBetaThreadNewAndRunParamsThreadMessagesContentUnion() { -} - // The role of the entity that is creating the message. Allowed values include: // // - `user`: Indicates the message is sent by an actual user and should be used in diff --git a/betathread_test.go b/betathread_test.go index c6b770b3..6a621cb8 100644 --- a/betathread_test.go +++ b/betathread_test.go @@ -11,7 +11,6 @@ import ( "github.com/openai/openai-go" "github.com/openai/openai-go/internal/testutil" "github.com/openai/openai-go/option" - "github.com/openai/openai-go/shared" ) func TestBetaThreadNewWithOptionalParams(t *testing.T) { @@ -28,7 +27,7 @@ func TestBetaThreadNewWithOptionalParams(t *testing.T) { ) _, err := client.Beta.Threads.New(context.TODO(), openai.BetaThreadNewParams{ Messages: openai.F([]openai.BetaThreadNewParamsMessage{{ - Content: openai.F[openai.BetaThreadNewParamsMessagesContentUnion](shared.UnionString("string")), + 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)}}), Role: openai.F(openai.BetaThreadNewParamsMessagesRoleUser), Attachments: openai.F([]openai.BetaThreadNewParamsMessagesAttachment{{ FileID: openai.F("file_id"), @@ -60,7 +59,7 @@ func TestBetaThreadNewWithOptionalParams(t *testing.T) { }}), Metadata: openai.F[any](map[string]interface{}{}), }, { - Content: openai.F[openai.BetaThreadNewParamsMessagesContentUnion](shared.UnionString("string")), + 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)}}), Role: openai.F(openai.BetaThreadNewParamsMessagesRoleUser), Attachments: openai.F([]openai.BetaThreadNewParamsMessagesAttachment{{ FileID: openai.F("file_id"), @@ -92,7 +91,7 @@ func TestBetaThreadNewWithOptionalParams(t *testing.T) { }}), Metadata: openai.F[any](map[string]interface{}{}), }, { - Content: openai.F[openai.BetaThreadNewParamsMessagesContentUnion](shared.UnionString("string")), + 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)}}), Role: openai.F(openai.BetaThreadNewParamsMessagesRoleUser), Attachments: openai.F([]openai.BetaThreadNewParamsMessagesAttachment{{ FileID: openai.F("file_id"), @@ -253,7 +252,7 @@ func TestBetaThreadNewAndRunWithOptionalParams(t *testing.T) { Temperature: openai.F(1.000000), Thread: openai.F(openai.BetaThreadNewAndRunParamsThread{ Messages: openai.F([]openai.BetaThreadNewAndRunParamsThreadMessage{{ - Content: openai.F[openai.BetaThreadNewAndRunParamsThreadMessagesContentUnion](shared.UnionString("string")), + 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)}}), Role: openai.F(openai.BetaThreadNewAndRunParamsThreadMessagesRoleUser), Attachments: openai.F([]openai.BetaThreadNewAndRunParamsThreadMessagesAttachment{{ FileID: openai.F("file_id"), @@ -285,7 +284,7 @@ func TestBetaThreadNewAndRunWithOptionalParams(t *testing.T) { }}), Metadata: openai.F[any](map[string]interface{}{}), }, { - Content: openai.F[openai.BetaThreadNewAndRunParamsThreadMessagesContentUnion](shared.UnionString("string")), + 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)}}), Role: openai.F(openai.BetaThreadNewAndRunParamsThreadMessagesRoleUser), Attachments: openai.F([]openai.BetaThreadNewAndRunParamsThreadMessagesAttachment{{ FileID: openai.F("file_id"), @@ -317,7 +316,7 @@ func TestBetaThreadNewAndRunWithOptionalParams(t *testing.T) { }}), Metadata: openai.F[any](map[string]interface{}{}), }, { - Content: openai.F[openai.BetaThreadNewAndRunParamsThreadMessagesContentUnion](shared.UnionString("string")), + 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)}}), Role: openai.F(openai.BetaThreadNewAndRunParamsThreadMessagesRoleUser), Attachments: openai.F([]openai.BetaThreadNewAndRunParamsThreadMessagesAttachment{{ FileID: openai.F("file_id"), diff --git a/betathreadmessage.go b/betathreadmessage.go index 093bfd96..1f719eae 100644 --- a/betathreadmessage.go +++ b/betathreadmessage.go @@ -1945,8 +1945,11 @@ func (r TextDeltaBlockType) IsKnown() bool { } type BetaThreadMessageNewParams struct { - // The text contents of the message. - Content param.Field[BetaThreadMessageNewParamsContentUnion] `json:"content,required"` + // An array of content parts with a defined type, each can be of type `text` or + // images can be passed with `image_url` or `image_file`. Image types are only + // supported on + // [Vision-compatible models](https://platform.openai.com/docs/models/overview). + Content param.Field[[]MessageContentPartParamUnion] `json:"content,required"` // The role of the entity that is creating the message. Allowed values include: // // - `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) { return apijson.MarshalRoot(r) } -// The text contents of the message. -// -// Satisfied by [shared.UnionString], -// [BetaThreadMessageNewParamsContentArrayOfContentParts]. -type BetaThreadMessageNewParamsContentUnion interface { - ImplementsBetaThreadMessageNewParamsContentUnion() -} - -type BetaThreadMessageNewParamsContentArrayOfContentParts []MessageContentPartParamUnion - -func (r BetaThreadMessageNewParamsContentArrayOfContentParts) ImplementsBetaThreadMessageNewParamsContentUnion() { -} - // The role of the entity that is creating the message. Allowed values include: // // - `user`: Indicates the message is sent by an actual user and should be used in diff --git a/betathreadmessage_test.go b/betathreadmessage_test.go index b3ec6620..26d1a495 100644 --- a/betathreadmessage_test.go +++ b/betathreadmessage_test.go @@ -11,7 +11,6 @@ import ( "github.com/openai/openai-go" "github.com/openai/openai-go/internal/testutil" "github.com/openai/openai-go/option" - "github.com/openai/openai-go/shared" ) func TestBetaThreadMessageNewWithOptionalParams(t *testing.T) { @@ -30,7 +29,7 @@ func TestBetaThreadMessageNewWithOptionalParams(t *testing.T) { context.TODO(), "thread_id", openai.BetaThreadMessageNewParams{ - Content: openai.F[openai.BetaThreadMessageNewParamsContentUnion](shared.UnionString("string")), + 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)}}), Role: openai.F(openai.BetaThreadMessageNewParamsRoleUser), Attachments: openai.F([]openai.BetaThreadMessageNewParamsAttachment{{ FileID: openai.F("file_id"), diff --git a/betathreadrun.go b/betathreadrun.go index da4833c8..e211dc66 100644 --- a/betathreadrun.go +++ b/betathreadrun.go @@ -727,8 +727,11 @@ func (r BetaThreadRunNewParams) MarshalJSON() (data []byte, err error) { } type BetaThreadRunNewParamsAdditionalMessage struct { - // The text contents of the message. - Content param.Field[BetaThreadRunNewParamsAdditionalMessagesContentUnion] `json:"content,required"` + // An array of content parts with a defined type, each can be of type `text` or + // images can be passed with `image_url` or `image_file`. Image types are only + // supported on + // [Vision-compatible models](https://platform.openai.com/docs/models/overview). + Content param.Field[[]MessageContentPartParamUnion] `json:"content,required"` // The role of the entity that is creating the message. Allowed values include: // // - `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 return apijson.MarshalRoot(r) } -// The text contents of the message. -// -// Satisfied by [shared.UnionString], -// [BetaThreadRunNewParamsAdditionalMessagesContentArrayOfContentParts]. -type BetaThreadRunNewParamsAdditionalMessagesContentUnion interface { - ImplementsBetaThreadRunNewParamsAdditionalMessagesContentUnion() -} - -type BetaThreadRunNewParamsAdditionalMessagesContentArrayOfContentParts []MessageContentPartParamUnion - -func (r BetaThreadRunNewParamsAdditionalMessagesContentArrayOfContentParts) ImplementsBetaThreadRunNewParamsAdditionalMessagesContentUnion() { -} - // The role of the entity that is creating the message. Allowed values include: // // - `user`: Indicates the message is sent by an actual user and should be used in diff --git a/betathreadrun_test.go b/betathreadrun_test.go index 4d7b9f85..6950ec30 100644 --- a/betathreadrun_test.go +++ b/betathreadrun_test.go @@ -11,7 +11,6 @@ import ( "github.com/openai/openai-go" "github.com/openai/openai-go/internal/testutil" "github.com/openai/openai-go/option" - "github.com/openai/openai-go/shared" ) func TestBetaThreadRunNewWithOptionalParams(t *testing.T) { @@ -33,7 +32,7 @@ func TestBetaThreadRunNewWithOptionalParams(t *testing.T) { AssistantID: openai.F("assistant_id"), AdditionalInstructions: openai.F("additional_instructions"), AdditionalMessages: openai.F([]openai.BetaThreadRunNewParamsAdditionalMessage{{ - Content: openai.F[openai.BetaThreadRunNewParamsAdditionalMessagesContentUnion](shared.UnionString("string")), + 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)}}), Role: openai.F(openai.BetaThreadRunNewParamsAdditionalMessagesRoleUser), Attachments: openai.F([]openai.BetaThreadRunNewParamsAdditionalMessagesAttachment{{ FileID: openai.F("file_id"), @@ -65,7 +64,7 @@ func TestBetaThreadRunNewWithOptionalParams(t *testing.T) { }}), Metadata: openai.F[any](map[string]interface{}{}), }, { - Content: openai.F[openai.BetaThreadRunNewParamsAdditionalMessagesContentUnion](shared.UnionString("string")), + 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)}}), Role: openai.F(openai.BetaThreadRunNewParamsAdditionalMessagesRoleUser), Attachments: openai.F([]openai.BetaThreadRunNewParamsAdditionalMessagesAttachment{{ FileID: openai.F("file_id"), @@ -97,7 +96,7 @@ func TestBetaThreadRunNewWithOptionalParams(t *testing.T) { }}), Metadata: openai.F[any](map[string]interface{}{}), }, { - Content: openai.F[openai.BetaThreadRunNewParamsAdditionalMessagesContentUnion](shared.UnionString("string")), + 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)}}), Role: openai.F(openai.BetaThreadRunNewParamsAdditionalMessagesRoleUser), Attachments: openai.F([]openai.BetaThreadRunNewParamsAdditionalMessagesAttachment{{ FileID: openai.F("file_id"), diff --git a/chatcompletion.go b/chatcompletion.go index ed0b0185..864910b3 100644 --- a/chatcompletion.go +++ b/chatcompletion.go @@ -226,7 +226,7 @@ type ChatCompletionAssistantMessageParam struct { Role param.Field[ChatCompletionAssistantMessageParamRole] `json:"role,required"` // The contents of the assistant message. Required unless `tool_calls` or // `function_call` is specified. - Content param.Field[ChatCompletionAssistantMessageParamContentUnion] `json:"content"` + Content param.Field[[]ChatCompletionAssistantMessageParamContentUnion] `json:"content"` // Deprecated and replaced by `tool_calls`. The name and arguments of a function // that should be called, as generated by the model. FunctionCall param.Field[ChatCompletionAssistantMessageParamFunctionCall] `json:"function_call"` @@ -260,54 +260,40 @@ func (r ChatCompletionAssistantMessageParamRole) IsKnown() bool { return false } -// The contents of the assistant message. Required unless `tool_calls` or -// `function_call` is specified. -// -// Satisfied by [shared.UnionString], -// [ChatCompletionAssistantMessageParamContentArrayOfContentParts]. -type ChatCompletionAssistantMessageParamContentUnion interface { - ImplementsChatCompletionAssistantMessageParamContentUnion() -} - -type ChatCompletionAssistantMessageParamContentArrayOfContentParts []ChatCompletionAssistantMessageParamContentArrayOfContentPartsUnionItem - -func (r ChatCompletionAssistantMessageParamContentArrayOfContentParts) ImplementsChatCompletionAssistantMessageParamContentUnion() { -} - -type ChatCompletionAssistantMessageParamContentArrayOfContentPart struct { +type ChatCompletionAssistantMessageParamContent struct { // The type of the content part. - Type param.Field[ChatCompletionAssistantMessageParamContentArrayOfContentPartsType] `json:"type,required"` + Type param.Field[ChatCompletionAssistantMessageParamContentType] `json:"type,required"` // The text content. Text param.Field[string] `json:"text"` // The refusal message generated by the model. Refusal param.Field[string] `json:"refusal"` } -func (r ChatCompletionAssistantMessageParamContentArrayOfContentPart) MarshalJSON() (data []byte, err error) { +func (r ChatCompletionAssistantMessageParamContent) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -func (r ChatCompletionAssistantMessageParamContentArrayOfContentPart) implementsChatCompletionAssistantMessageParamContentArrayOfContentPartsUnionItem() { +func (r ChatCompletionAssistantMessageParamContent) implementsChatCompletionAssistantMessageParamContentUnion() { } // Satisfied by [ChatCompletionContentPartTextParam], // [ChatCompletionContentPartRefusalParam], -// [ChatCompletionAssistantMessageParamContentArrayOfContentPart]. -type ChatCompletionAssistantMessageParamContentArrayOfContentPartsUnionItem interface { - implementsChatCompletionAssistantMessageParamContentArrayOfContentPartsUnionItem() +// [ChatCompletionAssistantMessageParamContent]. +type ChatCompletionAssistantMessageParamContentUnion interface { + implementsChatCompletionAssistantMessageParamContentUnion() } // The type of the content part. -type ChatCompletionAssistantMessageParamContentArrayOfContentPartsType string +type ChatCompletionAssistantMessageParamContentType string const ( - ChatCompletionAssistantMessageParamContentArrayOfContentPartsTypeText ChatCompletionAssistantMessageParamContentArrayOfContentPartsType = "text" - ChatCompletionAssistantMessageParamContentArrayOfContentPartsTypeRefusal ChatCompletionAssistantMessageParamContentArrayOfContentPartsType = "refusal" + ChatCompletionAssistantMessageParamContentTypeText ChatCompletionAssistantMessageParamContentType = "text" + ChatCompletionAssistantMessageParamContentTypeRefusal ChatCompletionAssistantMessageParamContentType = "refusal" ) -func (r ChatCompletionAssistantMessageParamContentArrayOfContentPartsType) IsKnown() bool { +func (r ChatCompletionAssistantMessageParamContentType) IsKnown() bool { switch r { - case ChatCompletionAssistantMessageParamContentArrayOfContentPartsTypeText, ChatCompletionAssistantMessageParamContentArrayOfContentPartsTypeRefusal: + case ChatCompletionAssistantMessageParamContentTypeText, ChatCompletionAssistantMessageParamContentTypeRefusal: return true } return false @@ -760,10 +746,7 @@ func (r ChatCompletionContentPartRefusalParam) MarshalJSON() (data []byte, err e return apijson.MarshalRoot(r) } -func (r ChatCompletionContentPartRefusalParam) implementsChatCompletionAssistantMessageParamContentArrayOfContentPartsUnionItem() { -} - -func (r ChatCompletionContentPartRefusalParam) implementsChatCompletionAssistantMessageParamContentArrayOfContentPartsUnion() { +func (r ChatCompletionContentPartRefusalParam) implementsChatCompletionAssistantMessageParamContentUnion() { } // The type of the content part. @@ -792,14 +775,11 @@ func (r ChatCompletionContentPartTextParam) MarshalJSON() (data []byte, err erro return apijson.MarshalRoot(r) } -func (r ChatCompletionContentPartTextParam) implementsChatCompletionAssistantMessageParamContentArrayOfContentPartsUnionItem() { +func (r ChatCompletionContentPartTextParam) implementsChatCompletionAssistantMessageParamContentUnion() { } func (r ChatCompletionContentPartTextParam) implementsChatCompletionContentPartUnionParam() {} -func (r ChatCompletionContentPartTextParam) implementsChatCompletionAssistantMessageParamContentArrayOfContentPartsUnion() { -} - // The type of the content part. type ChatCompletionContentPartTextType string @@ -1140,7 +1120,7 @@ func (r ChatCompletionStreamOptionsParam) MarshalJSON() (data []byte, err error) type ChatCompletionSystemMessageParam struct { // The contents of the system message. - Content param.Field[ChatCompletionSystemMessageParamContentUnion] `json:"content,required"` + Content param.Field[[]ChatCompletionContentPartTextParam] `json:"content,required"` // The role of the messages author, in this case `system`. Role param.Field[ChatCompletionSystemMessageParamRole] `json:"role,required"` // An optional name for the participant. Provides the model information to @@ -1154,19 +1134,6 @@ func (r ChatCompletionSystemMessageParam) MarshalJSON() (data []byte, err error) func (r ChatCompletionSystemMessageParam) implementsChatCompletionMessageParamUnion() {} -// The contents of the system message. -// -// Satisfied by [shared.UnionString], -// [ChatCompletionSystemMessageParamContentArrayOfContentParts]. -type ChatCompletionSystemMessageParamContentUnion interface { - ImplementsChatCompletionSystemMessageParamContentUnion() -} - -type ChatCompletionSystemMessageParamContentArrayOfContentParts []ChatCompletionContentPartTextParam - -func (r ChatCompletionSystemMessageParamContentArrayOfContentParts) ImplementsChatCompletionSystemMessageParamContentUnion() { -} - // The role of the messages author, in this case `system`. type ChatCompletionSystemMessageParamRole string @@ -1317,7 +1284,7 @@ func (r ChatCompletionToolChoiceOptionString) implementsChatCompletionToolChoice type ChatCompletionToolMessageParam struct { // The contents of the tool message. - Content param.Field[ChatCompletionToolMessageParamContentUnion] `json:"content,required"` + Content param.Field[[]ChatCompletionContentPartTextParam] `json:"content,required"` // The role of the messages author, in this case `tool`. Role param.Field[ChatCompletionToolMessageParamRole] `json:"role,required"` // Tool call that this message is responding to. @@ -1330,19 +1297,6 @@ func (r ChatCompletionToolMessageParam) MarshalJSON() (data []byte, err error) { func (r ChatCompletionToolMessageParam) implementsChatCompletionMessageParamUnion() {} -// The contents of the tool message. -// -// Satisfied by [shared.UnionString], -// [ChatCompletionToolMessageParamContentArrayOfContentParts]. -type ChatCompletionToolMessageParamContentUnion interface { - ImplementsChatCompletionToolMessageParamContentUnion() -} - -type ChatCompletionToolMessageParamContentArrayOfContentParts []ChatCompletionContentPartTextParam - -func (r ChatCompletionToolMessageParamContentArrayOfContentParts) ImplementsChatCompletionToolMessageParamContentUnion() { -} - // The role of the messages author, in this case `tool`. type ChatCompletionToolMessageParamRole string @@ -1360,7 +1314,7 @@ func (r ChatCompletionToolMessageParamRole) IsKnown() bool { type ChatCompletionUserMessageParam struct { // The contents of the user message. - Content param.Field[ChatCompletionUserMessageParamContentUnion] `json:"content,required"` + Content param.Field[[]ChatCompletionContentPartUnionParam] `json:"content,required"` // The role of the messages author, in this case `user`. Role param.Field[ChatCompletionUserMessageParamRole] `json:"role,required"` // An optional name for the participant. Provides the model information to @@ -1374,19 +1328,6 @@ func (r ChatCompletionUserMessageParam) MarshalJSON() (data []byte, err error) { func (r ChatCompletionUserMessageParam) implementsChatCompletionMessageParamUnion() {} -// The contents of the user message. -// -// Satisfied by [shared.UnionString], -// [ChatCompletionUserMessageParamContentArrayOfContentParts]. -type ChatCompletionUserMessageParamContentUnion interface { - ImplementsChatCompletionUserMessageParamContentUnion() -} - -type ChatCompletionUserMessageParamContentArrayOfContentParts []ChatCompletionContentPartUnionParam - -func (r ChatCompletionUserMessageParamContentArrayOfContentParts) ImplementsChatCompletionUserMessageParamContentUnion() { -} - // The role of the messages author, in this case `user`. type ChatCompletionUserMessageParamRole string diff --git a/chatcompletion_test.go b/chatcompletion_test.go index e477aa9d..12af4e73 100644 --- a/chatcompletion_test.go +++ b/chatcompletion_test.go @@ -28,7 +28,7 @@ func TestChatCompletionNewWithOptionalParams(t *testing.T) { ) _, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionSystemMessageParam{ - Content: openai.F[openai.ChatCompletionSystemMessageParamContentUnion](shared.UnionString("string")), + Content: openai.F([]openai.ChatCompletionContentPartTextParam{{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), Role: openai.F(openai.ChatCompletionSystemMessageParamRoleSystem), Name: openai.F("name"), }}), diff --git a/client_test.go b/client_test.go index 2027fab5..9e28c53d 100644 --- a/client_test.go +++ b/client_test.go @@ -12,7 +12,6 @@ import ( "github.com/openai/openai-go" "github.com/openai/openai-go/internal" "github.com/openai/openai-go/option" - "github.com/openai/openai-go/shared" ) type closureTransport struct { @@ -40,7 +39,7 @@ func TestUserAgentHeader(t *testing.T) { client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{ Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), - Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("Say this is a test")), + Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), Model: openai.F(openai.ChatModelGPT4o), }) @@ -69,7 +68,7 @@ func TestRetryAfter(t *testing.T) { res, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{ Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), - Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("Say this is a test")), + Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), Model: openai.F(openai.ChatModelGPT4o), }) @@ -101,7 +100,7 @@ func TestRetryAfterMs(t *testing.T) { res, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{ Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), - Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("Say this is a test")), + Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), Model: openai.F(openai.ChatModelGPT4o), }) @@ -129,7 +128,7 @@ func TestContextCancel(t *testing.T) { res, err := client.Chat.Completions.New(cancelCtx, openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{ Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), - Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("Say this is a test")), + Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), Model: openai.F(openai.ChatModelGPT4o), }) @@ -154,7 +153,7 @@ func TestContextCancelDelay(t *testing.T) { res, err := client.Chat.Completions.New(cancelCtx, openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{ Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), - Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("Say this is a test")), + Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), Model: openai.F(openai.ChatModelGPT4o), }) @@ -185,7 +184,7 @@ func TestContextDeadline(t *testing.T) { res, err := client.Chat.Completions.New(deadlineCtx, openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{ Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), - Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("Say this is a test")), + Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), Model: openai.F(openai.ChatModelGPT4o), }) diff --git a/shared/union.go b/shared/union.go index 7bab9fa3..9197f98c 100644 --- a/shared/union.go +++ b/shared/union.go @@ -4,19 +4,11 @@ package shared type UnionString string -func (UnionString) ImplementsCompletionNewParamsPromptUnion() {} -func (UnionString) ImplementsCompletionNewParamsStopUnion() {} -func (UnionString) ImplementsChatCompletionAssistantMessageParamContentUnion() {} -func (UnionString) ImplementsChatCompletionSystemMessageParamContentUnion() {} -func (UnionString) ImplementsChatCompletionUserMessageParamContentUnion() {} -func (UnionString) ImplementsChatCompletionToolMessageParamContentUnion() {} -func (UnionString) ImplementsChatCompletionNewParamsStopUnion() {} -func (UnionString) ImplementsEmbeddingNewParamsInputUnion() {} -func (UnionString) ImplementsModerationNewParamsInputUnion() {} -func (UnionString) ImplementsBetaThreadNewParamsMessagesContentUnion() {} -func (UnionString) ImplementsBetaThreadNewAndRunParamsThreadMessagesContentUnion() {} -func (UnionString) ImplementsBetaThreadRunNewParamsAdditionalMessagesContentUnion() {} -func (UnionString) ImplementsBetaThreadMessageNewParamsContentUnion() {} +func (UnionString) ImplementsCompletionNewParamsPromptUnion() {} +func (UnionString) ImplementsCompletionNewParamsStopUnion() {} +func (UnionString) ImplementsChatCompletionNewParamsStopUnion() {} +func (UnionString) ImplementsEmbeddingNewParamsInputUnion() {} +func (UnionString) ImplementsModerationNewParamsInputUnion() {} type UnionInt int64 diff --git a/usage_test.go b/usage_test.go index 15512ac0..1fc45049 100644 --- a/usage_test.go +++ b/usage_test.go @@ -10,7 +10,6 @@ import ( "github.com/openai/openai-go" "github.com/openai/openai-go/internal/testutil" "github.com/openai/openai-go/option" - "github.com/openai/openai-go/shared" ) func TestUsage(t *testing.T) { @@ -28,7 +27,7 @@ func TestUsage(t *testing.T) { _, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{ Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionUserMessageParam{ Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), - Content: openai.F[openai.ChatCompletionUserMessageParamContentUnion](shared.UnionString("Say this is a test")), + Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), Model: openai.F(openai.ChatModelGPT4o), })