diff --git a/.release-please-manifest.json b/.release-please-manifest.json index c76b581..54d8088 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-beta.6" + ".": "0.1.0-beta.7" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b29792..2d01448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 0.1.0-beta.7 (2025-04-07) + +Full Changelog: [v0.1.0-beta.6...v0.1.0-beta.7](https://github.com/openai/openai-go/compare/v0.1.0-beta.6...v0.1.0-beta.7) + +### Features + +* **client:** make response union's AsAny method type safe ([#352](https://github.com/openai/openai-go/issues/352)) ([1252f56](https://github.com/openai/openai-go/commit/1252f56c917e57d6d2b031501b2ff5f89f87cf87)) + + +### Chores + +* **docs:** doc improvements ([#350](https://github.com/openai/openai-go/issues/350)) ([80debc8](https://github.com/openai/openai-go/commit/80debc824eaacb4b07c8f3e8b1d0488d860d5be5)) + ## 0.1.0-beta.6 (2025-04-04) Full Changelog: [v0.1.0-beta.5...v0.1.0-beta.6](https://github.com/openai/openai-go/compare/v0.1.0-beta.5...v0.1.0-beta.6) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e2120a6..95426be 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ To set up the repository, run: ```sh $ ./scripts/bootstrap -$ ./scripts/build +$ ./scripts/lint ``` This will install all the required dependencies and build the SDK. diff --git a/README.md b/README.md index d6cb4c8..5224ac2 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Or to pin the version: ```sh -go get -u 'github.com/openai/openai-go@v0.1.0-beta.6' +go get -u 'github.com/openai/openai-go@v0.1.0-beta.7' ``` diff --git a/audiotranscription.go b/audiotranscription.go index 2844195..e52f74f 100644 --- a/audiotranscription.go +++ b/audiotranscription.go @@ -140,6 +140,16 @@ type TranscriptionStreamEventUnion struct { } `json:"-"` } +// anyTranscriptionStreamEvent is implemented by each variant of +// [TranscriptionStreamEventUnion] to add type safety for the return type of +// [TranscriptionStreamEventUnion.AsAny] +type anyTranscriptionStreamEvent interface { + implTranscriptionStreamEventUnion() +} + +func (TranscriptionTextDeltaEvent) implTranscriptionStreamEventUnion() {} +func (TranscriptionTextDoneEvent) implTranscriptionStreamEventUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := TranscriptionStreamEventUnion.AsAny().(type) { @@ -148,7 +158,7 @@ type TranscriptionStreamEventUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u TranscriptionStreamEventUnion) AsAny() any { +func (u TranscriptionStreamEventUnion) AsAny() anyTranscriptionStreamEvent { switch u.Type { case "transcript.text.delta": return u.AsTranscriptTextDelta() @@ -352,6 +362,8 @@ type AudioTranscriptionNewParams struct { // Either or both of these options are supported: `word`, or `segment`. Note: There // is no additional latency for segment timestamps, but generating word timestamps // incurs additional latency. + // + // Any of "word", "segment". TimestampGranularities []string `json:"timestamp_granularities,omitzero"` paramObj } diff --git a/betaassistant.go b/betaassistant.go index 9539eff..d97a5e2 100644 --- a/betaassistant.go +++ b/betaassistant.go @@ -344,6 +344,38 @@ type AssistantStreamEventUnion struct { } `json:"-"` } +// anyAssistantStreamEvent is implemented by each variant of +// [AssistantStreamEventUnion] to add type safety for the return type of +// [AssistantStreamEventUnion.AsAny] +type anyAssistantStreamEvent interface { + implAssistantStreamEventUnion() +} + +func (AssistantStreamEventThreadCreated) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunCreated) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunQueued) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunInProgress) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunRequiresAction) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunCompleted) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunIncomplete) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunFailed) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunCancelling) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunCancelled) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunExpired) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunStepCreated) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunStepInProgress) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunStepDelta) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunStepCompleted) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunStepFailed) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunStepCancelled) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadRunStepExpired) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadMessageCreated) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadMessageInProgress) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadMessageDelta) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadMessageCompleted) implAssistantStreamEventUnion() {} +func (AssistantStreamEventThreadMessageIncomplete) implAssistantStreamEventUnion() {} +func (AssistantStreamEventErrorEvent) implAssistantStreamEventUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := AssistantStreamEventUnion.AsAny().(type) { @@ -374,7 +406,7 @@ type AssistantStreamEventUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u AssistantStreamEventUnion) AsAny() any { +func (u AssistantStreamEventUnion) AsAny() anyAssistantStreamEvent { switch u.Event { case "thread.created": return u.AsThreadCreated() @@ -1347,6 +1379,16 @@ type AssistantToolUnion struct { } `json:"-"` } +// anyAssistantTool is implemented by each variant of [AssistantToolUnion] to add +// type safety for the return type of [AssistantToolUnion.AsAny] +type anyAssistantTool interface { + implAssistantToolUnion() +} + +func (CodeInterpreterTool) implAssistantToolUnion() {} +func (FileSearchTool) implAssistantToolUnion() {} +func (FunctionTool) implAssistantToolUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := AssistantToolUnion.AsAny().(type) { @@ -1356,7 +1398,7 @@ type AssistantToolUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u AssistantToolUnion) AsAny() any { +func (u AssistantToolUnion) AsAny() anyAssistantTool { switch u.Type { case "code_interpreter": return u.AsCodeInterpreter() diff --git a/betathreadmessage.go b/betathreadmessage.go index 204bef9..5e897ad 100644 --- a/betathreadmessage.go +++ b/betathreadmessage.go @@ -160,6 +160,15 @@ type AnnotationUnion struct { } `json:"-"` } +// anyAnnotation is implemented by each variant of [AnnotationUnion] to add type +// safety for the return type of [AnnotationUnion.AsAny] +type anyAnnotation interface { + implAnnotationUnion() +} + +func (FileCitationAnnotation) implAnnotationUnion() {} +func (FilePathAnnotation) implAnnotationUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := AnnotationUnion.AsAny().(type) { @@ -168,7 +177,7 @@ type AnnotationUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u AnnotationUnion) AsAny() any { +func (u AnnotationUnion) AsAny() anyAnnotation { switch u.Type { case "file_citation": return u.AsFileCitation() @@ -224,6 +233,15 @@ type AnnotationDeltaUnion struct { } `json:"-"` } +// anyAnnotationDelta is implemented by each variant of [AnnotationDeltaUnion] to +// add type safety for the return type of [AnnotationDeltaUnion.AsAny] +type anyAnnotationDelta interface { + implAnnotationDeltaUnion() +} + +func (FileCitationDeltaAnnotation) implAnnotationDeltaUnion() {} +func (FilePathDeltaAnnotation) implAnnotationDeltaUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := AnnotationDeltaUnion.AsAny().(type) { @@ -232,7 +250,7 @@ type AnnotationDeltaUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u AnnotationDeltaUnion) AsAny() any { +func (u AnnotationDeltaUnion) AsAny() anyAnnotationDelta { switch u.Type { case "file_citation": return u.AsFileCitation() @@ -1022,6 +1040,17 @@ type MessageContentUnion struct { } `json:"-"` } +// anyMessageContent is implemented by each variant of [MessageContentUnion] to add +// type safety for the return type of [MessageContentUnion.AsAny] +type anyMessageContent interface { + implMessageContentUnion() +} + +func (ImageFileContentBlock) implMessageContentUnion() {} +func (ImageURLContentBlock) implMessageContentUnion() {} +func (TextContentBlock) implMessageContentUnion() {} +func (RefusalContentBlock) implMessageContentUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := MessageContentUnion.AsAny().(type) { @@ -1032,7 +1061,7 @@ type MessageContentUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u MessageContentUnion) AsAny() any { +func (u MessageContentUnion) AsAny() anyMessageContent { switch u.Type { case "image_file": return u.AsImageFile() @@ -1103,6 +1132,18 @@ type MessageContentDeltaUnion struct { } `json:"-"` } +// anyMessageContentDelta is implemented by each variant of +// [MessageContentDeltaUnion] to add type safety for the return type of +// [MessageContentDeltaUnion.AsAny] +type anyMessageContentDelta interface { + implMessageContentDeltaUnion() +} + +func (ImageFileDeltaBlock) implMessageContentDeltaUnion() {} +func (TextDeltaBlock) implMessageContentDeltaUnion() {} +func (RefusalDeltaBlock) implMessageContentDeltaUnion() {} +func (ImageURLDeltaBlock) implMessageContentDeltaUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := MessageContentDeltaUnion.AsAny().(type) { @@ -1113,7 +1154,7 @@ type MessageContentDeltaUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u MessageContentDeltaUnion) AsAny() any { +func (u MessageContentDeltaUnion) AsAny() anyMessageContentDelta { switch u.Type { case "image_file": return u.AsImageFile() diff --git a/betathreadrunstep.go b/betathreadrunstep.go index b81dd26..5d6f650 100644 --- a/betathreadrunstep.go +++ b/betathreadrunstep.go @@ -232,6 +232,18 @@ type CodeInterpreterToolCallCodeInterpreterOutputUnion struct { } `json:"-"` } +// anyCodeInterpreterToolCallCodeInterpreterOutput is implemented by each variant +// of [CodeInterpreterToolCallCodeInterpreterOutputUnion] to add type safety for +// the return type of [CodeInterpreterToolCallCodeInterpreterOutputUnion.AsAny] +type anyCodeInterpreterToolCallCodeInterpreterOutput interface { + implCodeInterpreterToolCallCodeInterpreterOutputUnion() +} + +func (CodeInterpreterToolCallCodeInterpreterOutputLogs) implCodeInterpreterToolCallCodeInterpreterOutputUnion() { +} +func (CodeInterpreterToolCallCodeInterpreterOutputImage) implCodeInterpreterToolCallCodeInterpreterOutputUnion() { +} + // Use the following switch statement to find the correct variant // // switch variant := CodeInterpreterToolCallCodeInterpreterOutputUnion.AsAny().(type) { @@ -240,7 +252,7 @@ type CodeInterpreterToolCallCodeInterpreterOutputUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u CodeInterpreterToolCallCodeInterpreterOutputUnion) AsAny() any { +func (u CodeInterpreterToolCallCodeInterpreterOutputUnion) AsAny() anyCodeInterpreterToolCallCodeInterpreterOutput { switch u.Type { case "logs": return u.AsLogs() @@ -405,6 +417,17 @@ type CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion struct { } `json:"-"` } +// anyCodeInterpreterToolCallDeltaCodeInterpreterOutput is implemented by each +// variant of [CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion] to add type +// safety for the return type of +// [CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion.AsAny] +type anyCodeInterpreterToolCallDeltaCodeInterpreterOutput interface { + implCodeInterpreterToolCallDeltaCodeInterpreterOutputUnion() +} + +func (CodeInterpreterLogs) implCodeInterpreterToolCallDeltaCodeInterpreterOutputUnion() {} +func (CodeInterpreterOutputImage) implCodeInterpreterToolCallDeltaCodeInterpreterOutputUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion.AsAny().(type) { @@ -413,7 +436,7 @@ type CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) AsAny() any { +func (u CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) AsAny() anyCodeInterpreterToolCallDeltaCodeInterpreterOutput { switch u.Type { case "logs": return u.AsLogs() @@ -879,6 +902,16 @@ type RunStepStepDetailsUnion struct { } `json:"-"` } +// anyRunStepStepDetails is implemented by each variant of +// [RunStepStepDetailsUnion] to add type safety for the return type of +// [RunStepStepDetailsUnion.AsAny] +type anyRunStepStepDetails interface { + implRunStepStepDetailsUnion() +} + +func (MessageCreationStepDetails) implRunStepStepDetailsUnion() {} +func (ToolCallsStepDetails) implRunStepStepDetailsUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := RunStepStepDetailsUnion.AsAny().(type) { @@ -887,7 +920,7 @@ type RunStepStepDetailsUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u RunStepStepDetailsUnion) AsAny() any { +func (u RunStepStepDetailsUnion) AsAny() anyRunStepStepDetails { switch u.Type { case "message_creation": return u.AsMessageCreation() @@ -988,6 +1021,16 @@ type RunStepDeltaStepDetailsUnion struct { } `json:"-"` } +// anyRunStepDeltaStepDetails is implemented by each variant of +// [RunStepDeltaStepDetailsUnion] to add type safety for the return type of +// [RunStepDeltaStepDetailsUnion.AsAny] +type anyRunStepDeltaStepDetails interface { + implRunStepDeltaStepDetailsUnion() +} + +func (RunStepDeltaMessageDelta) implRunStepDeltaStepDetailsUnion() {} +func (ToolCallDeltaObject) implRunStepDeltaStepDetailsUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := RunStepDeltaStepDetailsUnion.AsAny().(type) { @@ -996,7 +1039,7 @@ type RunStepDeltaStepDetailsUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u RunStepDeltaStepDetailsUnion) AsAny() any { +func (u RunStepDeltaStepDetailsUnion) AsAny() anyRunStepDeltaStepDetails { switch u.Type { case "message_creation": return u.AsMessageCreation() @@ -1120,6 +1163,16 @@ type ToolCallUnion struct { } `json:"-"` } +// anyToolCall is implemented by each variant of [ToolCallUnion] to add type safety +// for the return type of [ToolCallUnion.AsAny] +type anyToolCall interface { + implToolCallUnion() +} + +func (CodeInterpreterToolCall) implToolCallUnion() {} +func (FileSearchToolCall) implToolCallUnion() {} +func (FunctionToolCall) implToolCallUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ToolCallUnion.AsAny().(type) { @@ -1129,7 +1182,7 @@ type ToolCallUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ToolCallUnion) AsAny() any { +func (u ToolCallUnion) AsAny() anyToolCall { switch u.Type { case "code_interpreter": return u.AsCodeInterpreter() @@ -1192,6 +1245,16 @@ type ToolCallDeltaUnion struct { } `json:"-"` } +// anyToolCallDelta is implemented by each variant of [ToolCallDeltaUnion] to add +// type safety for the return type of [ToolCallDeltaUnion.AsAny] +type anyToolCallDelta interface { + implToolCallDeltaUnion() +} + +func (CodeInterpreterToolCallDelta) implToolCallDeltaUnion() {} +func (FileSearchToolCallDelta) implToolCallDeltaUnion() {} +func (FunctionToolCallDelta) implToolCallDeltaUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ToolCallDeltaUnion.AsAny().(type) { @@ -1201,7 +1264,7 @@ type ToolCallDeltaUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ToolCallDeltaUnion) AsAny() any { +func (u ToolCallDeltaUnion) AsAny() anyToolCallDelta { switch u.Type { case "code_interpreter": return u.AsCodeInterpreter() diff --git a/chatcompletion.go b/chatcompletion.go index 4d27f5f..9d878ef 100644 --- a/chatcompletion.go +++ b/chatcompletion.go @@ -2288,6 +2288,8 @@ type ChatCompletionNewParams struct { // this model generate both text and audio responses, you can use: // // `["text", "audio"]` + // + // Any of "text", "audio". Modalities []string `json:"modalities,omitzero"` // **o-series models only** // diff --git a/internal/version.go b/internal/version.go index 9071a92..200c4d3 100644 --- a/internal/version.go +++ b/internal/version.go @@ -2,4 +2,4 @@ package internal -const PackageVersion = "0.1.0-beta.6" // x-release-please-version +const PackageVersion = "0.1.0-beta.7" // x-release-please-version diff --git a/moderation.go b/moderation.go index 924e07c..54ff7b8 100644 --- a/moderation.go +++ b/moderation.go @@ -146,30 +146,56 @@ func (r *ModerationCategories) UnmarshalJSON(data []byte) error { // A list of the categories along with the input type(s) that the score applies to. type ModerationCategoryAppliedInputTypes struct { // The applied input type(s) for the category 'harassment'. + // + // Any of "text". Harassment []string `json:"harassment,required"` // The applied input type(s) for the category 'harassment/threatening'. + // + // Any of "text". HarassmentThreatening []string `json:"harassment/threatening,required"` // The applied input type(s) for the category 'hate'. + // + // Any of "text". Hate []string `json:"hate,required"` // The applied input type(s) for the category 'hate/threatening'. + // + // Any of "text". HateThreatening []string `json:"hate/threatening,required"` // The applied input type(s) for the category 'illicit'. + // + // Any of "text". Illicit []string `json:"illicit,required"` // The applied input type(s) for the category 'illicit/violent'. + // + // Any of "text". IllicitViolent []string `json:"illicit/violent,required"` // The applied input type(s) for the category 'self-harm'. + // + // Any of "text", "image". SelfHarm []string `json:"self-harm,required"` // The applied input type(s) for the category 'self-harm/instructions'. + // + // Any of "text", "image". SelfHarmInstructions []string `json:"self-harm/instructions,required"` // The applied input type(s) for the category 'self-harm/intent'. + // + // Any of "text", "image". SelfHarmIntent []string `json:"self-harm/intent,required"` // The applied input type(s) for the category 'sexual'. + // + // Any of "text", "image". Sexual []string `json:"sexual,required"` // The applied input type(s) for the category 'sexual/minors'. + // + // Any of "text". SexualMinors []string `json:"sexual/minors,required"` // The applied input type(s) for the category 'violence'. + // + // Any of "text", "image". Violence []string `json:"violence,required"` // The applied input type(s) for the category 'violence/graphic'. + // + // Any of "text", "image". ViolenceGraphic []string `json:"violence/graphic,required"` // Metadata for the response, check the presence of optional fields with the // [resp.Field.IsPresent] method. diff --git a/responses/response.go b/responses/response.go index 1e47683..89f6d23 100644 --- a/responses/response.go +++ b/responses/response.go @@ -300,6 +300,8 @@ func (r *FileSearchTool) UnmarshalJSON(data []byte) error { return apijson.UnmarshalRoot(data, r) } +func (FileSearchTool) implAssistantToolUnion() {} + // ToParam converts this FileSearchTool to a FileSearchToolParam. // // Warning: the fields of the param type will not be present. ToParam should only @@ -525,6 +527,8 @@ func (r *FunctionTool) UnmarshalJSON(data []byte) error { return apijson.UnmarshalRoot(data, r) } +func (FunctionTool) implAssistantToolUnion() {} + // ToParam converts this FunctionTool to a FunctionToolParam. // // Warning: the fields of the param type will not be present. ToParam should only @@ -1066,6 +1070,16 @@ type ResponseCodeInterpreterToolCallResultUnion struct { } `json:"-"` } +// anyResponseCodeInterpreterToolCallResult is implemented by each variant of +// [ResponseCodeInterpreterToolCallResultUnion] to add type safety for the return +// type of [ResponseCodeInterpreterToolCallResultUnion.AsAny] +type anyResponseCodeInterpreterToolCallResult interface { + implResponseCodeInterpreterToolCallResultUnion() +} + +func (ResponseCodeInterpreterToolCallResultLogs) implResponseCodeInterpreterToolCallResultUnion() {} +func (ResponseCodeInterpreterToolCallResultFiles) implResponseCodeInterpreterToolCallResultUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseCodeInterpreterToolCallResultUnion.AsAny().(type) { @@ -1074,7 +1088,7 @@ type ResponseCodeInterpreterToolCallResultUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseCodeInterpreterToolCallResultUnion) AsAny() any { +func (u ResponseCodeInterpreterToolCallResultUnion) AsAny() anyResponseCodeInterpreterToolCallResult { switch u.Type { case "logs": return u.AsLogs() @@ -1292,6 +1306,23 @@ type ResponseComputerToolCallActionUnion struct { } `json:"-"` } +// anyResponseComputerToolCallAction is implemented by each variant of +// [ResponseComputerToolCallActionUnion] to add type safety for the return type of +// [ResponseComputerToolCallActionUnion.AsAny] +type anyResponseComputerToolCallAction interface { + implResponseComputerToolCallActionUnion() +} + +func (ResponseComputerToolCallActionClick) implResponseComputerToolCallActionUnion() {} +func (ResponseComputerToolCallActionDoubleClick) implResponseComputerToolCallActionUnion() {} +func (ResponseComputerToolCallActionDrag) implResponseComputerToolCallActionUnion() {} +func (ResponseComputerToolCallActionKeypress) implResponseComputerToolCallActionUnion() {} +func (ResponseComputerToolCallActionMove) implResponseComputerToolCallActionUnion() {} +func (ResponseComputerToolCallActionScreenshot) implResponseComputerToolCallActionUnion() {} +func (ResponseComputerToolCallActionScroll) implResponseComputerToolCallActionUnion() {} +func (ResponseComputerToolCallActionType) implResponseComputerToolCallActionUnion() {} +func (ResponseComputerToolCallActionWait) implResponseComputerToolCallActionUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseComputerToolCallActionUnion.AsAny().(type) { @@ -1307,7 +1338,7 @@ type ResponseComputerToolCallActionUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseComputerToolCallActionUnion) AsAny() any { +func (u ResponseComputerToolCallActionUnion) AsAny() anyResponseComputerToolCallAction { switch u.Type { case "click": return u.AsClick() @@ -2408,6 +2439,16 @@ type ResponseContentPartAddedEventPartUnion struct { } `json:"-"` } +// anyResponseContentPartAddedEventPart is implemented by each variant of +// [ResponseContentPartAddedEventPartUnion] to add type safety for the return type +// of [ResponseContentPartAddedEventPartUnion.AsAny] +type anyResponseContentPartAddedEventPart interface { + implResponseContentPartAddedEventPartUnion() +} + +func (ResponseOutputText) implResponseContentPartAddedEventPartUnion() {} +func (ResponseOutputRefusal) implResponseContentPartAddedEventPartUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseContentPartAddedEventPartUnion.AsAny().(type) { @@ -2416,7 +2457,7 @@ type ResponseContentPartAddedEventPartUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseContentPartAddedEventPartUnion) AsAny() any { +func (u ResponseContentPartAddedEventPartUnion) AsAny() anyResponseContentPartAddedEventPart { switch u.Type { case "output_text": return u.AsOutputText() @@ -2499,6 +2540,16 @@ type ResponseContentPartDoneEventPartUnion struct { } `json:"-"` } +// anyResponseContentPartDoneEventPart is implemented by each variant of +// [ResponseContentPartDoneEventPartUnion] to add type safety for the return type +// of [ResponseContentPartDoneEventPartUnion.AsAny] +type anyResponseContentPartDoneEventPart interface { + implResponseContentPartDoneEventPartUnion() +} + +func (ResponseOutputText) implResponseContentPartDoneEventPartUnion() {} +func (ResponseOutputRefusal) implResponseContentPartDoneEventPartUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseContentPartDoneEventPartUnion.AsAny().(type) { @@ -2507,7 +2558,7 @@ type ResponseContentPartDoneEventPartUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseContentPartDoneEventPartUnion) AsAny() any { +func (u ResponseContentPartDoneEventPartUnion) AsAny() anyResponseContentPartDoneEventPart { switch u.Type { case "output_text": return u.AsOutputText() @@ -2988,6 +3039,15 @@ type ResponseFormatTextConfigUnion struct { } `json:"-"` } +// anyResponseFormatTextConfig is implemented by each variant of +// [ResponseFormatTextConfigUnion] to add type safety for the return type of +// [ResponseFormatTextConfigUnion.AsAny] +type anyResponseFormatTextConfig interface { + ImplResponseFormatTextConfigUnion() +} + +func (ResponseFormatTextJSONSchemaConfig) ImplResponseFormatTextConfigUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseFormatTextConfigUnion.AsAny().(type) { @@ -2997,7 +3057,7 @@ type ResponseFormatTextConfigUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseFormatTextConfigUnion) AsAny() any { +func (u ResponseFormatTextConfigUnion) AsAny() anyResponseFormatTextConfig { switch u.Type { case "text": return u.AsText() @@ -3614,6 +3674,17 @@ type ResponseInputContentUnion struct { } `json:"-"` } +// anyResponseInputContent is implemented by each variant of +// [ResponseInputContentUnion] to add type safety for the return type of +// [ResponseInputContentUnion.AsAny] +type anyResponseInputContent interface { + implResponseInputContentUnion() +} + +func (ResponseInputText) implResponseInputContentUnion() {} +func (ResponseInputImage) implResponseInputContentUnion() {} +func (ResponseInputFile) implResponseInputContentUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseInputContentUnion.AsAny().(type) { @@ -3623,7 +3694,7 @@ type ResponseInputContentUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseInputContentUnion) AsAny() any { +func (u ResponseInputContentUnion) AsAny() anyResponseInputContent { switch u.Type { case "input_text": return u.AsInputText() @@ -4753,6 +4824,21 @@ type ResponseItemUnion struct { } `json:"-"` } +// anyResponseItem is implemented by each variant of [ResponseItemUnion] to add +// type safety for the return type of [ResponseItemUnion.AsAny] +type anyResponseItem interface { + implResponseItemUnion() +} + +func (ResponseInputMessageItem) implResponseItemUnion() {} +func (ResponseOutputMessage) implResponseItemUnion() {} +func (ResponseFileSearchToolCall) implResponseItemUnion() {} +func (ResponseComputerToolCall) implResponseItemUnion() {} +func (ResponseComputerToolCallOutputItem) implResponseItemUnion() {} +func (ResponseFunctionWebSearch) implResponseItemUnion() {} +func (ResponseFunctionToolCallItem) implResponseItemUnion() {} +func (ResponseFunctionToolCallOutputItem) implResponseItemUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseItemUnion.AsAny().(type) { @@ -4767,7 +4853,7 @@ type ResponseItemUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseItemUnion) AsAny() any { +func (u ResponseItemUnion) AsAny() anyResponseItem { switch u.Type { case "message": return u.AsOutputMessage() @@ -4943,6 +5029,20 @@ type ResponseOutputItemUnion struct { } `json:"-"` } +// anyResponseOutputItem is implemented by each variant of +// [ResponseOutputItemUnion] to add type safety for the return type of +// [ResponseOutputItemUnion.AsAny] +type anyResponseOutputItem interface { + implResponseOutputItemUnion() +} + +func (ResponseOutputMessage) implResponseOutputItemUnion() {} +func (ResponseFileSearchToolCall) implResponseOutputItemUnion() {} +func (ResponseFunctionToolCall) implResponseOutputItemUnion() {} +func (ResponseFunctionWebSearch) implResponseOutputItemUnion() {} +func (ResponseComputerToolCall) implResponseOutputItemUnion() {} +func (ResponseReasoningItem) implResponseOutputItemUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseOutputItemUnion.AsAny().(type) { @@ -4955,7 +5055,7 @@ type ResponseOutputItemUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseOutputItemUnion) AsAny() any { +func (u ResponseOutputItemUnion) AsAny() anyResponseOutputItem { switch u.Type { case "message": return u.AsMessage() @@ -5128,6 +5228,16 @@ type ResponseOutputMessageContentUnion struct { } `json:"-"` } +// anyResponseOutputMessageContent is implemented by each variant of +// [ResponseOutputMessageContentUnion] to add type safety for the return type of +// [ResponseOutputMessageContentUnion.AsAny] +type anyResponseOutputMessageContent interface { + implResponseOutputMessageContentUnion() +} + +func (ResponseOutputText) implResponseOutputMessageContentUnion() {} +func (ResponseOutputRefusal) implResponseOutputMessageContentUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseOutputMessageContentUnion.AsAny().(type) { @@ -5136,7 +5246,7 @@ type ResponseOutputMessageContentUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseOutputMessageContentUnion) AsAny() any { +func (u ResponseOutputMessageContentUnion) AsAny() anyResponseOutputMessageContent { switch u.Type { case "output_text": return u.AsOutputText() @@ -5402,6 +5512,17 @@ type ResponseOutputTextAnnotationUnion struct { } `json:"-"` } +// anyResponseOutputTextAnnotation is implemented by each variant of +// [ResponseOutputTextAnnotationUnion] to add type safety for the return type of +// [ResponseOutputTextAnnotationUnion.AsAny] +type anyResponseOutputTextAnnotation interface { + implResponseOutputTextAnnotationUnion() +} + +func (ResponseOutputTextAnnotationFileCitation) implResponseOutputTextAnnotationUnion() {} +func (ResponseOutputTextAnnotationURLCitation) implResponseOutputTextAnnotationUnion() {} +func (ResponseOutputTextAnnotationFilePath) implResponseOutputTextAnnotationUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseOutputTextAnnotationUnion.AsAny().(type) { @@ -5411,7 +5532,7 @@ type ResponseOutputTextAnnotationUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseOutputTextAnnotationUnion) AsAny() any { +func (u ResponseOutputTextAnnotationUnion) AsAny() anyResponseOutputTextAnnotation { switch u.Type { case "file_citation": return u.AsFileCitation() @@ -6031,6 +6152,46 @@ type ResponseStreamEventUnion struct { } `json:"-"` } +// anyResponseStreamEvent is implemented by each variant of +// [ResponseStreamEventUnion] to add type safety for the return type of +// [ResponseStreamEventUnion.AsAny] +type anyResponseStreamEvent interface { + implResponseStreamEventUnion() +} + +func (ResponseAudioDeltaEvent) implResponseStreamEventUnion() {} +func (ResponseAudioDoneEvent) implResponseStreamEventUnion() {} +func (ResponseAudioTranscriptDeltaEvent) implResponseStreamEventUnion() {} +func (ResponseAudioTranscriptDoneEvent) implResponseStreamEventUnion() {} +func (ResponseCodeInterpreterCallCodeDeltaEvent) implResponseStreamEventUnion() {} +func (ResponseCodeInterpreterCallCodeDoneEvent) implResponseStreamEventUnion() {} +func (ResponseCodeInterpreterCallCompletedEvent) implResponseStreamEventUnion() {} +func (ResponseCodeInterpreterCallInProgressEvent) implResponseStreamEventUnion() {} +func (ResponseCodeInterpreterCallInterpretingEvent) implResponseStreamEventUnion() {} +func (ResponseCompletedEvent) implResponseStreamEventUnion() {} +func (ResponseContentPartAddedEvent) implResponseStreamEventUnion() {} +func (ResponseContentPartDoneEvent) implResponseStreamEventUnion() {} +func (ResponseCreatedEvent) implResponseStreamEventUnion() {} +func (ResponseErrorEvent) implResponseStreamEventUnion() {} +func (ResponseFileSearchCallCompletedEvent) implResponseStreamEventUnion() {} +func (ResponseFileSearchCallInProgressEvent) implResponseStreamEventUnion() {} +func (ResponseFileSearchCallSearchingEvent) implResponseStreamEventUnion() {} +func (ResponseFunctionCallArgumentsDeltaEvent) implResponseStreamEventUnion() {} +func (ResponseFunctionCallArgumentsDoneEvent) implResponseStreamEventUnion() {} +func (ResponseInProgressEvent) implResponseStreamEventUnion() {} +func (ResponseFailedEvent) implResponseStreamEventUnion() {} +func (ResponseIncompleteEvent) implResponseStreamEventUnion() {} +func (ResponseOutputItemAddedEvent) implResponseStreamEventUnion() {} +func (ResponseOutputItemDoneEvent) implResponseStreamEventUnion() {} +func (ResponseRefusalDeltaEvent) implResponseStreamEventUnion() {} +func (ResponseRefusalDoneEvent) implResponseStreamEventUnion() {} +func (ResponseTextAnnotationDeltaEvent) implResponseStreamEventUnion() {} +func (ResponseTextDeltaEvent) implResponseStreamEventUnion() {} +func (ResponseTextDoneEvent) implResponseStreamEventUnion() {} +func (ResponseWebSearchCallCompletedEvent) implResponseStreamEventUnion() {} +func (ResponseWebSearchCallInProgressEvent) implResponseStreamEventUnion() {} +func (ResponseWebSearchCallSearchingEvent) implResponseStreamEventUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := ResponseStreamEventUnion.AsAny().(type) { @@ -6069,7 +6230,7 @@ type ResponseStreamEventUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseStreamEventUnion) AsAny() any { +func (u ResponseStreamEventUnion) AsAny() anyResponseStreamEvent { switch u.Type { case "response.audio.delta": return u.AsResponseAudioDelta() @@ -6408,6 +6569,20 @@ type ResponseTextAnnotationDeltaEventAnnotationUnion struct { } `json:"-"` } +// anyResponseTextAnnotationDeltaEventAnnotation is implemented by each variant of +// [ResponseTextAnnotationDeltaEventAnnotationUnion] to add type safety for the +// return type of [ResponseTextAnnotationDeltaEventAnnotationUnion.AsAny] +type anyResponseTextAnnotationDeltaEventAnnotation interface { + implResponseTextAnnotationDeltaEventAnnotationUnion() +} + +func (ResponseTextAnnotationDeltaEventAnnotationFileCitation) implResponseTextAnnotationDeltaEventAnnotationUnion() { +} +func (ResponseTextAnnotationDeltaEventAnnotationURLCitation) implResponseTextAnnotationDeltaEventAnnotationUnion() { +} +func (ResponseTextAnnotationDeltaEventAnnotationFilePath) implResponseTextAnnotationDeltaEventAnnotationUnion() { +} + // Use the following switch statement to find the correct variant // // switch variant := ResponseTextAnnotationDeltaEventAnnotationUnion.AsAny().(type) { @@ -6417,7 +6592,7 @@ type ResponseTextAnnotationDeltaEventAnnotationUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u ResponseTextAnnotationDeltaEventAnnotationUnion) AsAny() any { +func (u ResponseTextAnnotationDeltaEventAnnotationUnion) AsAny() anyResponseTextAnnotationDeltaEventAnnotation { switch u.Type { case "file_citation": return u.AsFileCitation() diff --git a/shared/shared.go b/shared/shared.go index adae5e9..907af6f 100644 --- a/shared/shared.go +++ b/shared/shared.go @@ -534,6 +534,8 @@ func (r *ResponseFormatJSONObject) UnmarshalJSON(data []byte) error { return apijson.UnmarshalRoot(data, r) } +func (ResponseFormatJSONObject) ImplResponseFormatTextConfigUnion() {} + // ToParam converts this ResponseFormatJSONObject to a // ResponseFormatJSONObjectParam. // @@ -708,6 +710,8 @@ func (r *ResponseFormatText) UnmarshalJSON(data []byte) error { return apijson.UnmarshalRoot(data, r) } +func (ResponseFormatText) ImplResponseFormatTextConfigUnion() {} + // ToParam converts this ResponseFormatText to a ResponseFormatTextParam. // // Warning: the fields of the param type will not be present. ToParam should only diff --git a/vectorstore.go b/vectorstore.go index 0d69790..29af5da 100644 --- a/vectorstore.go +++ b/vectorstore.go @@ -184,6 +184,16 @@ type FileChunkingStrategyUnion struct { } `json:"-"` } +// anyFileChunkingStrategy is implemented by each variant of +// [FileChunkingStrategyUnion] to add type safety for the return type of +// [FileChunkingStrategyUnion.AsAny] +type anyFileChunkingStrategy interface { + implFileChunkingStrategyUnion() +} + +func (StaticFileChunkingStrategyObject) implFileChunkingStrategyUnion() {} +func (OtherFileChunkingStrategyObject) implFileChunkingStrategyUnion() {} + // Use the following switch statement to find the correct variant // // switch variant := FileChunkingStrategyUnion.AsAny().(type) { @@ -192,7 +202,7 @@ type FileChunkingStrategyUnion struct { // default: // fmt.Errorf("no variant present") // } -func (u FileChunkingStrategyUnion) AsAny() any { +func (u FileChunkingStrategyUnion) AsAny() anyFileChunkingStrategy { switch u.Type { case "static": return u.AsStatic()