diff --git a/.release-please-manifest.json b/.release-please-manifest.json index aff3ead3..bf7fe4fa 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-beta.2" + ".": "0.1.0-beta.3" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 7011b57a..426a77c6 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,4 @@ configured_endpoints: 80 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-5ad6884898c07591750dde560118baf7074a59aecd1f367f930c5e42b04e848a.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-6663c59193eb95b201e492de17dcbd5e126ba03d18ce66287a3e2c632ca56fe7.yml +openapi_spec_hash: 7996d2c34cc44fe2ce9ffe93c0ab774e +config_hash: e25e31d8446b6bc0e3ef7103b6993cce diff --git a/CHANGELOG.md b/CHANGELOG.md index a197995c..4a9acd0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## 0.1.0-beta.3 (2025-03-28) + +Full Changelog: [v0.1.0-beta.2...v0.1.0-beta.3](https://github.com/openai/openai-go/compare/v0.1.0-beta.2...v0.1.0-beta.3) + +### ⚠ BREAKING CHANGES + +* **client:** add enums ([#327](https://github.com/openai/openai-go/issues/327)) + +### Features + +* **api:** add `get /chat/completions` endpoint ([e8ed116](https://github.com/openai/openai-go/commit/e8ed1168576c885cb26fbf819b9c8d24975749bd)) +* **api:** add `get /responses/{response_id}/input_items` endpoint ([8870c26](https://github.com/openai/openai-go/commit/8870c26f010a596adcf37ac10dba096bdd4394e3)) + + +### Bug Fixes + +* **client:** add enums ([#327](https://github.com/openai/openai-go/issues/327)) ([b0e3afb](https://github.com/openai/openai-go/commit/b0e3afbd6f18fd9fc2a5ea9174bd7ec0ac0614db)) + + +### Chores + +* add hash of OpenAPI spec/config inputs to .stats.yml ([104b786](https://github.com/openai/openai-go/commit/104b7861bb025514999b143f7d1de45d2dab659f)) +* add request options to client tests ([#321](https://github.com/openai/openai-go/issues/321)) ([f5239ce](https://github.com/openai/openai-go/commit/f5239ceecf36835341eac5121ed1770020c4806a)) +* **api:** updates to supported Voice IDs ([#325](https://github.com/openai/openai-go/issues/325)) ([477727a](https://github.com/openai/openai-go/commit/477727a44b0fb72493c4749cc60171e0d30f98ec)) +* **docs:** improve security documentation ([#319](https://github.com/openai/openai-go/issues/319)) ([0271053](https://github.com/openai/openai-go/commit/027105363ab30ac3e189234908169faf94e0ca49)) +* fix typos ([#324](https://github.com/openai/openai-go/issues/324)) ([dba15f7](https://github.com/openai/openai-go/commit/dba15f74d63814ce16f778e1017a209a42f46179)) + ## 0.1.0-beta.2 (2025-03-22) Full Changelog: [v0.1.0-beta.1...v0.1.0-beta.2](https://github.com/openai/openai-go/compare/v0.1.0-beta.1...v0.1.0-beta.2) diff --git a/README.md b/README.md index 145bb857..e71033ab 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.2' +go get -u 'github.com/openai/openai-go@v0.1.0-beta.3' ``` @@ -310,8 +310,8 @@ To send `null` instead of a struct, use `param.NullObj[T]()`, where `T` is a str To send a custom value instead of a struct, use `param.OverrideObj[T](value)`. To override request structs contain a `.WithExtraFields(map[string]any)` method which can be used to -send non-conforming fields in the request body. Extra fields take higher precedence than normal -fields. +send non-conforming fields in the request body. Extra fields overwrite any struct fields with a matching +key, so only use with trusted data. ```go params := FooParams{ @@ -527,7 +527,7 @@ To handle errors, we recommend that you use the `errors.As` pattern: ```go _, err := client.FineTuning.Jobs.New(context.TODO(), openai.FineTuningJobNewParams{ - Model: "babbage-002", + Model: openai.FineTuningJobNewParamsModelBabbage002, TrainingFile: "file-abc123", }) if err != nil { diff --git a/audiospeech.go b/audiospeech.go index aef19cc4..e5802717 100644 --- a/audiospeech.go +++ b/audiospeech.go @@ -54,12 +54,9 @@ type AudioSpeechNewParams struct { // `tts-1`, `tts-1-hd` or `gpt-4o-mini-tts`. Model SpeechModel `json:"model,omitzero,required"` // The voice to use when generating the audio. Supported voices are `alloy`, `ash`, - // `coral`, `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the - // voices are available in the + // `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`, `shimmer`, and + // `verse`. Previews of the voices are available in the // [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options). - // - // Any of "alloy", "ash", "coral", "echo", "fable", "onyx", "nova", "sage", - // "shimmer". Voice AudioSpeechNewParamsVoice `json:"voice,omitzero,required"` // Control the voice of your generated audio with additional instructions. Does not // work with `tts-1` or `tts-1-hd`. @@ -85,14 +82,15 @@ func (r AudioSpeechNewParams) MarshalJSON() (data []byte, err error) { } // The voice to use when generating the audio. Supported voices are `alloy`, `ash`, -// `coral`, `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the -// voices are available in the +// `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`, `shimmer`, and +// `verse`. Previews of the voices are available in the // [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options). type AudioSpeechNewParamsVoice string const ( AudioSpeechNewParamsVoiceAlloy AudioSpeechNewParamsVoice = "alloy" AudioSpeechNewParamsVoiceAsh AudioSpeechNewParamsVoice = "ash" + AudioSpeechNewParamsVoiceBallad AudioSpeechNewParamsVoice = "ballad" AudioSpeechNewParamsVoiceCoral AudioSpeechNewParamsVoice = "coral" AudioSpeechNewParamsVoiceEcho AudioSpeechNewParamsVoice = "echo" AudioSpeechNewParamsVoiceFable AudioSpeechNewParamsVoice = "fable" @@ -100,6 +98,7 @@ const ( AudioSpeechNewParamsVoiceNova AudioSpeechNewParamsVoice = "nova" AudioSpeechNewParamsVoiceSage AudioSpeechNewParamsVoice = "sage" AudioSpeechNewParamsVoiceShimmer AudioSpeechNewParamsVoice = "shimmer" + AudioSpeechNewParamsVoiceVerse AudioSpeechNewParamsVoice = "verse" ) // The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, diff --git a/betaassistant.go b/betaassistant.go index 37777df5..47a42183 100644 --- a/betaassistant.go +++ b/betaassistant.go @@ -2093,7 +2093,7 @@ type BetaAssistantUpdateParams struct { // see all of your available models, or see our // [Model overview](https://platform.openai.com/docs/models) for descriptions of // them. - Model string `json:"model,omitzero"` + Model BetaAssistantUpdateParamsModel `json:"model,omitzero"` // Specifies the format that the model must output. Compatible with // [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), // [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), @@ -2131,6 +2131,46 @@ func (r BetaAssistantUpdateParams) MarshalJSON() (data []byte, err error) { return param.MarshalObject(r, (*shadow)(&r)) } +// ID of the model to use. You can use the +// [List models](https://platform.openai.com/docs/api-reference/models/list) API to +// see all of your available models, or see our +// [Model overview](https://platform.openai.com/docs/models) for descriptions of +// them. +type BetaAssistantUpdateParamsModel string + +const ( + BetaAssistantUpdateParamsModelO3Mini BetaAssistantUpdateParamsModel = "o3-mini" + BetaAssistantUpdateParamsModelO3Mini2025_01_31 BetaAssistantUpdateParamsModel = "o3-mini-2025-01-31" + BetaAssistantUpdateParamsModelO1 BetaAssistantUpdateParamsModel = "o1" + BetaAssistantUpdateParamsModelO1_2024_12_17 BetaAssistantUpdateParamsModel = "o1-2024-12-17" + BetaAssistantUpdateParamsModelGPT4o BetaAssistantUpdateParamsModel = "gpt-4o" + BetaAssistantUpdateParamsModelGPT4o2024_11_20 BetaAssistantUpdateParamsModel = "gpt-4o-2024-11-20" + BetaAssistantUpdateParamsModelGPT4o2024_08_06 BetaAssistantUpdateParamsModel = "gpt-4o-2024-08-06" + BetaAssistantUpdateParamsModelGPT4o2024_05_13 BetaAssistantUpdateParamsModel = "gpt-4o-2024-05-13" + BetaAssistantUpdateParamsModelGPT4oMini BetaAssistantUpdateParamsModel = "gpt-4o-mini" + BetaAssistantUpdateParamsModelGPT4oMini2024_07_18 BetaAssistantUpdateParamsModel = "gpt-4o-mini-2024-07-18" + BetaAssistantUpdateParamsModelGPT4_5Preview BetaAssistantUpdateParamsModel = "gpt-4.5-preview" + BetaAssistantUpdateParamsModelGPT4_5Preview2025_02_27 BetaAssistantUpdateParamsModel = "gpt-4.5-preview-2025-02-27" + BetaAssistantUpdateParamsModelGPT4Turbo BetaAssistantUpdateParamsModel = "gpt-4-turbo" + BetaAssistantUpdateParamsModelGPT4Turbo2024_04_09 BetaAssistantUpdateParamsModel = "gpt-4-turbo-2024-04-09" + BetaAssistantUpdateParamsModelGPT4_0125Preview BetaAssistantUpdateParamsModel = "gpt-4-0125-preview" + BetaAssistantUpdateParamsModelGPT4TurboPreview BetaAssistantUpdateParamsModel = "gpt-4-turbo-preview" + BetaAssistantUpdateParamsModelGPT4_1106Preview BetaAssistantUpdateParamsModel = "gpt-4-1106-preview" + BetaAssistantUpdateParamsModelGPT4VisionPreview BetaAssistantUpdateParamsModel = "gpt-4-vision-preview" + BetaAssistantUpdateParamsModelGPT4 BetaAssistantUpdateParamsModel = "gpt-4" + BetaAssistantUpdateParamsModelGPT4_0314 BetaAssistantUpdateParamsModel = "gpt-4-0314" + BetaAssistantUpdateParamsModelGPT4_0613 BetaAssistantUpdateParamsModel = "gpt-4-0613" + BetaAssistantUpdateParamsModelGPT4_32k BetaAssistantUpdateParamsModel = "gpt-4-32k" + BetaAssistantUpdateParamsModelGPT4_32k0314 BetaAssistantUpdateParamsModel = "gpt-4-32k-0314" + BetaAssistantUpdateParamsModelGPT4_32k0613 BetaAssistantUpdateParamsModel = "gpt-4-32k-0613" + BetaAssistantUpdateParamsModelGPT3_5Turbo BetaAssistantUpdateParamsModel = "gpt-3.5-turbo" + BetaAssistantUpdateParamsModelGPT3_5Turbo16k BetaAssistantUpdateParamsModel = "gpt-3.5-turbo-16k" + BetaAssistantUpdateParamsModelGPT3_5Turbo0613 BetaAssistantUpdateParamsModel = "gpt-3.5-turbo-0613" + BetaAssistantUpdateParamsModelGPT3_5Turbo1106 BetaAssistantUpdateParamsModel = "gpt-3.5-turbo-1106" + BetaAssistantUpdateParamsModelGPT3_5Turbo0125 BetaAssistantUpdateParamsModel = "gpt-3.5-turbo-0125" + BetaAssistantUpdateParamsModelGPT3_5Turbo16k0613 BetaAssistantUpdateParamsModel = "gpt-3.5-turbo-16k-0613" +) + // A set of resources that are used by the assistant's tools. The resources are // specific to the type of tool. For example, the `code_interpreter` tool requires // a list of file IDs, while the `file_search` tool requires a list of vector store diff --git a/betaassistant_test.go b/betaassistant_test.go index 82fb99eb..37ef49d9 100644 --- a/betaassistant_test.go +++ b/betaassistant_test.go @@ -114,7 +114,7 @@ func TestBetaAssistantUpdateWithOptionalParams(t *testing.T) { Metadata: shared.MetadataParam{ "foo": "string", }, - Model: "o3-mini", + Model: openai.BetaAssistantUpdateParamsModelO3Mini, Name: openai.String("name"), ReasoningEffort: shared.ReasoningEffortLow, ResponseFormat: openai.AssistantResponseFormatOptionUnionParam{ diff --git a/betathread.go b/betathread.go index a9396556..79266379 100644 --- a/betathread.go +++ b/betathread.go @@ -403,6 +403,18 @@ func (r AssistantToolChoiceOptionUnion) ToParam() AssistantToolChoiceOptionUnion return param.OverrideObj[AssistantToolChoiceOptionUnionParam](r.RawJSON()) } +// `none` means the model will not call any tools and instead generates a message. +// `auto` means the model can pick between generating a message or calling one or +// more tools. `required` means the model must call one or more tools before +// responding to the user. +type AssistantToolChoiceOptionAuto string + +const ( + AssistantToolChoiceOptionAutoNone AssistantToolChoiceOptionAuto = "none" + AssistantToolChoiceOptionAutoAuto AssistantToolChoiceOptionAuto = "auto" + AssistantToolChoiceOptionAutoRequired AssistantToolChoiceOptionAuto = "required" +) + func AssistantToolChoiceOptionParamOfAssistantToolChoice(type_ AssistantToolChoiceType) AssistantToolChoiceOptionUnionParam { var variant AssistantToolChoiceParam variant.Type = type_ diff --git a/chatcompletion.go b/chatcompletion.go index 4cbd9fbc..88a999c0 100644 --- a/chatcompletion.go +++ b/chatcompletion.go @@ -500,8 +500,6 @@ type ChatCompletionAudioParam struct { Format ChatCompletionAudioParamFormat `json:"format,omitzero,required"` // The voice the model uses to respond. Supported voices are `alloy`, `ash`, // `ballad`, `coral`, `echo`, `sage`, and `shimmer`. - // - // Any of "alloy", "ash", "ballad", "coral", "echo", "sage", "shimmer", "verse". Voice ChatCompletionAudioParamVoice `json:"voice,omitzero,required"` paramObj } @@ -536,6 +534,9 @@ const ( ChatCompletionAudioParamVoiceBallad ChatCompletionAudioParamVoice = "ballad" ChatCompletionAudioParamVoiceCoral ChatCompletionAudioParamVoice = "coral" ChatCompletionAudioParamVoiceEcho ChatCompletionAudioParamVoice = "echo" + ChatCompletionAudioParamVoiceFable ChatCompletionAudioParamVoice = "fable" + ChatCompletionAudioParamVoiceOnyx ChatCompletionAudioParamVoice = "onyx" + ChatCompletionAudioParamVoiceNova ChatCompletionAudioParamVoice = "nova" ChatCompletionAudioParamVoiceSage ChatCompletionAudioParamVoice = "sage" ChatCompletionAudioParamVoiceShimmer ChatCompletionAudioParamVoice = "shimmer" ChatCompletionAudioParamVoiceVerse ChatCompletionAudioParamVoice = "verse" @@ -2071,6 +2072,17 @@ func (u ChatCompletionToolChoiceOptionUnionParam) GetType() *string { return nil } +// `none` means the model will not call any tool and instead generates a message. +// `auto` means the model can pick between generating a message or calling one or +// more tools. `required` means the model must call one or more tools. +type ChatCompletionToolChoiceOptionAuto string + +const ( + ChatCompletionToolChoiceOptionAutoNone ChatCompletionToolChoiceOptionAuto = "none" + ChatCompletionToolChoiceOptionAutoAuto ChatCompletionToolChoiceOptionAuto = "auto" + ChatCompletionToolChoiceOptionAutoRequired ChatCompletionToolChoiceOptionAuto = "required" +) + // The properties Content, Role, ToolCallID are required. type ChatCompletionToolMessageParam struct { // The contents of the tool message. @@ -2407,6 +2419,16 @@ func (u ChatCompletionNewParamsFunctionCallUnion) GetName() *string { return nil } +// `none` means the model will not call a function and instead generates a message. +// `auto` means the model can pick between generating a message or calling a +// function. +type ChatCompletionNewParamsFunctionCallFunctionCallMode string + +const ( + ChatCompletionNewParamsFunctionCallFunctionCallModeNone ChatCompletionNewParamsFunctionCallFunctionCallMode = "none" + ChatCompletionNewParamsFunctionCallFunctionCallModeAuto ChatCompletionNewParamsFunctionCallFunctionCallMode = "auto" +) + // Deprecated: deprecated // // The property Name is required. diff --git a/client_test.go b/client_test.go index 38b94119..9665679e 100644 --- a/client_test.go +++ b/client_test.go @@ -28,6 +28,7 @@ func (t *closureTransport) RoundTrip(req *http.Request) (*http.Response, error) func TestUserAgentHeader(t *testing.T) { var userAgent string client := openai.NewClient( + option.WithAPIKey("My API Key"), option.WithHTTPClient(&http.Client{ Transport: &closureTransport{ fn: func(req *http.Request) (*http.Response, error) { @@ -57,6 +58,7 @@ func TestUserAgentHeader(t *testing.T) { func TestRetryAfter(t *testing.T) { retryCountHeaders := make([]string, 0) client := openai.NewClient( + option.WithAPIKey("My API Key"), option.WithHTTPClient(&http.Client{ Transport: &closureTransport{ fn: func(req *http.Request) (*http.Response, error) { @@ -99,6 +101,7 @@ func TestRetryAfter(t *testing.T) { func TestDeleteRetryCountHeader(t *testing.T) { retryCountHeaders := make([]string, 0) client := openai.NewClient( + option.WithAPIKey("My API Key"), option.WithHTTPClient(&http.Client{ Transport: &closureTransport{ fn: func(req *http.Request) (*http.Response, error) { @@ -137,6 +140,7 @@ func TestDeleteRetryCountHeader(t *testing.T) { func TestOverwriteRetryCountHeader(t *testing.T) { retryCountHeaders := make([]string, 0) client := openai.NewClient( + option.WithAPIKey("My API Key"), option.WithHTTPClient(&http.Client{ Transport: &closureTransport{ fn: func(req *http.Request) (*http.Response, error) { @@ -175,6 +179,7 @@ func TestOverwriteRetryCountHeader(t *testing.T) { func TestRetryAfterMs(t *testing.T) { attempts := 0 client := openai.NewClient( + option.WithAPIKey("My API Key"), option.WithHTTPClient(&http.Client{ Transport: &closureTransport{ fn: func(req *http.Request) (*http.Response, error) { @@ -209,6 +214,7 @@ func TestRetryAfterMs(t *testing.T) { func TestContextCancel(t *testing.T) { client := openai.NewClient( + option.WithAPIKey("My API Key"), option.WithHTTPClient(&http.Client{ Transport: &closureTransport{ fn: func(req *http.Request) (*http.Response, error) { @@ -237,6 +243,7 @@ func TestContextCancel(t *testing.T) { func TestContextCancelDelay(t *testing.T) { client := openai.NewClient( + option.WithAPIKey("My API Key"), option.WithHTTPClient(&http.Client{ Transport: &closureTransport{ fn: func(req *http.Request) (*http.Response, error) { @@ -273,6 +280,7 @@ func TestContextDeadline(t *testing.T) { go func() { client := openai.NewClient( + option.WithAPIKey("My API Key"), option.WithHTTPClient(&http.Client{ Transport: &closureTransport{ fn: func(req *http.Request) (*http.Response, error) { @@ -318,6 +326,7 @@ func TestContextDeadlineStreaming(t *testing.T) { go func() { client := openai.NewClient( + option.WithAPIKey("My API Key"), option.WithHTTPClient(&http.Client{ Transport: &closureTransport{ fn: func(req *http.Request) (*http.Response, error) { @@ -371,6 +380,7 @@ func TestContextDeadlineStreamingWithRequestTimeout(t *testing.T) { go func() { client := openai.NewClient( + option.WithAPIKey("My API Key"), option.WithHTTPClient(&http.Client{ Transport: &closureTransport{ fn: func(req *http.Request) (*http.Response, error) { diff --git a/completion.go b/completion.go index 82fb57fd..c45e389c 100644 --- a/completion.go +++ b/completion.go @@ -258,7 +258,7 @@ type CompletionNewParams struct { // see all of your available models, or see our // [Model overview](https://platform.openai.com/docs/models) for descriptions of // them. - Model string `json:"model,omitzero,required"` + Model CompletionNewParamsModel `json:"model,omitzero,required"` // Generates `best_of` completions server-side and returns the "best" (the one with // the highest log probability per token). Results cannot be streamed. // @@ -361,6 +361,19 @@ func (r CompletionNewParams) MarshalJSON() (data []byte, err error) { return param.MarshalObject(r, (*shadow)(&r)) } +// ID of the model to use. You can use the +// [List models](https://platform.openai.com/docs/api-reference/models/list) API to +// see all of your available models, or see our +// [Model overview](https://platform.openai.com/docs/models) for descriptions of +// them. +type CompletionNewParamsModel string + +const ( + CompletionNewParamsModelGPT3_5TurboInstruct CompletionNewParamsModel = "gpt-3.5-turbo-instruct" + CompletionNewParamsModelDavinci002 CompletionNewParamsModel = "davinci-002" + CompletionNewParamsModelBabbage002 CompletionNewParamsModel = "babbage-002" +) + // Only one field can be non-zero. // // Use [param.IsOmitted] to confirm if a field is set. diff --git a/completion_test.go b/completion_test.go index 58fc4f81..5be40122 100644 --- a/completion_test.go +++ b/completion_test.go @@ -26,7 +26,7 @@ func TestCompletionNewWithOptionalParams(t *testing.T) { option.WithAPIKey("My API Key"), ) _, err := client.Completions.New(context.TODO(), openai.CompletionNewParams{ - Model: "gpt-3.5-turbo-instruct", + Model: openai.CompletionNewParamsModelGPT3_5TurboInstruct, Prompt: openai.CompletionNewParamsPromptUnion{ OfString: openai.String("This is a test."), }, diff --git a/finetuningjob.go b/finetuningjob.go index 1c6e4a3a..7436b776 100644 --- a/finetuningjob.go +++ b/finetuningjob.go @@ -917,7 +917,7 @@ func (r *FineTuningJobWandbIntegrationObject) UnmarshalJSON(data []byte) error { type FineTuningJobNewParams struct { // The name of the model to fine-tune. You can select one of the // [supported models](https://platform.openai.com/docs/guides/fine-tuning#which-models-can-be-fine-tuned). - Model string `json:"model,omitzero,required"` + Model FineTuningJobNewParamsModel `json:"model,omitzero,required"` // The ID of an uploaded file that contains training data. // // See [upload file](https://platform.openai.com/docs/api-reference/files/create) @@ -985,6 +985,17 @@ func (r FineTuningJobNewParams) MarshalJSON() (data []byte, err error) { return param.MarshalObject(r, (*shadow)(&r)) } +// The name of the model to fine-tune. You can select one of the +// [supported models](https://platform.openai.com/docs/guides/fine-tuning#which-models-can-be-fine-tuned). +type FineTuningJobNewParamsModel string + +const ( + FineTuningJobNewParamsModelBabbage002 FineTuningJobNewParamsModel = "babbage-002" + FineTuningJobNewParamsModelDavinci002 FineTuningJobNewParamsModel = "davinci-002" + FineTuningJobNewParamsModelGPT3_5Turbo FineTuningJobNewParamsModel = "gpt-3.5-turbo" + FineTuningJobNewParamsModelGPT4oMini FineTuningJobNewParamsModel = "gpt-4o-mini" +) + // The hyperparameters used for the fine-tuning job. This value is now deprecated // in favor of `method`, and should be passed in under the `method` parameter. // diff --git a/finetuningjob_test.go b/finetuningjob_test.go index 88905f46..7985283e 100644 --- a/finetuningjob_test.go +++ b/finetuningjob_test.go @@ -28,7 +28,7 @@ func TestFineTuningJobNewWithOptionalParams(t *testing.T) { option.WithAPIKey("My API Key"), ) _, err := client.FineTuning.Jobs.New(context.TODO(), openai.FineTuningJobNewParams{ - Model: "babbage-002", + Model: openai.FineTuningJobNewParamsModelBabbage002, TrainingFile: "file-abc123", Hyperparameters: openai.FineTuningJobNewParamsHyperparameters{ BatchSize: openai.FineTuningJobNewParamsHyperparametersBatchSizeUnion{ diff --git a/internal/requestconfig/requestconfig.go b/internal/requestconfig/requestconfig.go index 49cffcbd..3f48d94b 100644 --- a/internal/requestconfig/requestconfig.go +++ b/internal/requestconfig/requestconfig.go @@ -236,7 +236,7 @@ func shouldRetry(req *http.Request, res *http.Response) bool { return true } - // If the header explictly wants a retry behavior, respect that over the + // If the header explicitly wants a retry behavior, respect that over the // http status code. if res.Header.Get("x-should-retry") == "true" { return true diff --git a/internal/version.go b/internal/version.go index 93f653bc..53363fdb 100644 --- a/internal/version.go +++ b/internal/version.go @@ -2,4 +2,4 @@ package internal -const PackageVersion = "0.1.0-beta.2" // x-release-please-version +const PackageVersion = "0.1.0-beta.3" // x-release-please-version diff --git a/option/requestoption.go b/option/requestoption.go index a4350826..78ec1eda 100644 --- a/option/requestoption.go +++ b/option/requestoption.go @@ -24,6 +24,8 @@ import ( type RequestOption = requestconfig.RequestOption // WithBaseURL returns a RequestOption that sets the BaseURL for the client. +// +// For security reasons, ensure that the base URL is trusted. func WithBaseURL(base string) RequestOption { u, err := url.Parse(base) if err != nil { diff --git a/packages/param/option.go b/packages/param/option.go index 7add88c2..aee94e33 100644 --- a/packages/param/option.go +++ b/packages/param/option.go @@ -2,6 +2,7 @@ package param import ( "encoding/json" + "fmt" "reflect" "time" ) @@ -78,6 +79,16 @@ func (o Opt[T]) Or(v T) T { return v } +func (o Opt[T]) String() string { + if o.IsNull() { + return "null" + } + if s, ok := any(o.Value).(fmt.Stringer); ok { + return s.String() + } + return fmt.Sprintf("%v", o.Value) +} + // This is a sketchy way to implement time Formatting var timeType = reflect.TypeOf(time.Time{}) var timeTimeValueLoc, _ = reflect.TypeOf(Opt[time.Time]{}).FieldByName("Value") diff --git a/packages/param/param.go b/packages/param/param.go index 0a641aa6..4ffce959 100644 --- a/packages/param/param.go +++ b/packages/param/param.go @@ -94,8 +94,12 @@ func (m metadata) GetExtraFields() map[string]any { return nil } -func (m *metadata) WithExtraFields(fields map[string]any) { - m.any = metadataExtraFields(fields) +// WithExtraFields adds extra fields to the JSON object. +// +// WithExtraFields will override any existing fields with the same key. +// For security reasons, ensure this is only used with trusted input data. +func (m *metadata) WithExtraFields(extraFields map[string]any) { + m.any = metadataExtraFields(extraFields) } func (m *metadata) setMetadata(override any) { diff --git a/responses/inputitem.go b/responses/inputitem.go index d308ed55..7c92f1d1 100644 --- a/responses/inputitem.go +++ b/responses/inputitem.go @@ -104,6 +104,9 @@ type InputItemListParams struct { // A limit on the number of objects to be returned. Limit can range between 1 and // 100, and the default is 20. Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + // Additional fields to include in the response. See the `include` parameter for + // Response creation above for more information. + Include []ResponseIncludable `query:"include,omitzero" json:"-"` // The order to return the input items in. Default is `asc`. // // - `asc`: Return the input items in ascending order. diff --git a/responses/inputitem_test.go b/responses/inputitem_test.go index 5f57c5f5..06aedb7b 100644 --- a/responses/inputitem_test.go +++ b/responses/inputitem_test.go @@ -30,10 +30,11 @@ func TestInputItemListWithOptionalParams(t *testing.T) { context.TODO(), "response_id", responses.InputItemListParams{ - After: openai.String("after"), - Before: openai.String("before"), - Limit: openai.Int(0), - Order: responses.InputItemListParamsOrderAsc, + After: openai.String("after"), + Before: openai.String("before"), + Include: []responses.ResponseIncludable{responses.ResponseIncludableFileSearchCallResults}, + Limit: openai.Int(0), + Order: responses.InputItemListParamsOrderAsc, }, ) if err != nil { diff --git a/responses/response.go b/responses/response.go index a442ebc5..c82a07dc 100644 --- a/responses/response.go +++ b/responses/response.go @@ -577,8 +577,8 @@ type Response struct { // context. // // When using along with `previous_response_id`, the instructions from a previous - // response will be not be carried over to the next response. This makes it simple - // to swap out system (or developer) messages in new responses. + // response will not be carried over to the next response. This makes it simple to + // swap out system (or developer) messages in new responses. Instructions string `json:"instructions,required"` // Set of 16 key-value pairs that can be attached to an object. This can be useful // for storing additional information about the object in a structured format, and @@ -2971,18 +2971,18 @@ type ResponseFormatTextConfigUnion struct { // Any of "text", "json_schema", "json_object". Type string `json:"type"` // This field is from variant [ResponseFormatTextJSONSchemaConfig]. + Name string `json:"name"` + // This field is from variant [ResponseFormatTextJSONSchemaConfig]. Schema map[string]interface{} `json:"schema"` // This field is from variant [ResponseFormatTextJSONSchemaConfig]. Description string `json:"description"` // This field is from variant [ResponseFormatTextJSONSchemaConfig]. - Name string `json:"name"` - // This field is from variant [ResponseFormatTextJSONSchemaConfig]. Strict bool `json:"strict"` JSON struct { Type resp.Field + Name resp.Field Schema resp.Field Description resp.Field - Name resp.Field Strict resp.Field raw string } `json:"-"` @@ -3041,8 +3041,9 @@ func (r ResponseFormatTextConfigUnion) ToParam() ResponseFormatTextConfigUnionPa return param.OverrideObj[ResponseFormatTextConfigUnionParam](r.RawJSON()) } -func ResponseFormatTextConfigParamOfJSONSchema(schema map[string]interface{}) ResponseFormatTextConfigUnionParam { +func ResponseFormatTextConfigParamOfJSONSchema(name string, schema map[string]interface{}) ResponseFormatTextConfigUnionParam { var jsonSchema ResponseFormatTextJSONSchemaConfigParam + jsonSchema.Name = name jsonSchema.Schema = schema return ResponseFormatTextConfigUnionParam{OfJSONSchema: &jsonSchema} } @@ -3078,25 +3079,25 @@ func (u *ResponseFormatTextConfigUnionParam) asAny() any { } // Returns a pointer to the underlying variant's property, if present. -func (u ResponseFormatTextConfigUnionParam) GetSchema() map[string]interface{} { +func (u ResponseFormatTextConfigUnionParam) GetName() *string { if vt := u.OfJSONSchema; vt != nil { - return vt.Schema + return &vt.Name } return nil } // Returns a pointer to the underlying variant's property, if present. -func (u ResponseFormatTextConfigUnionParam) GetDescription() *string { - if vt := u.OfJSONSchema; vt != nil && vt.Description.IsPresent() { - return &vt.Description.Value +func (u ResponseFormatTextConfigUnionParam) GetSchema() map[string]interface{} { + if vt := u.OfJSONSchema; vt != nil { + return vt.Schema } return nil } // Returns a pointer to the underlying variant's property, if present. -func (u ResponseFormatTextConfigUnionParam) GetName() *string { - if vt := u.OfJSONSchema; vt != nil && vt.Name.IsPresent() { - return &vt.Name.Value +func (u ResponseFormatTextConfigUnionParam) GetDescription() *string { + if vt := u.OfJSONSchema; vt != nil && vt.Description.IsPresent() { + return &vt.Description.Value } return nil } @@ -3146,6 +3147,9 @@ func init() { // more about // [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs). type ResponseFormatTextJSONSchemaConfig struct { + // The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores + // and dashes, with a maximum length of 64. + Name string `json:"name,required"` // The schema for the response format, described as a JSON Schema object. Learn how // to build JSON schemas [here](https://json-schema.org/). Schema map[string]interface{} `json:"schema,required"` @@ -3154,9 +3158,6 @@ type ResponseFormatTextJSONSchemaConfig struct { // A description of what the response format is for, used by the model to determine // how to respond in the format. Description string `json:"description"` - // The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores - // and dashes, with a maximum length of 64. - Name string `json:"name"` // Whether to enable strict schema adherence when generating the output. If set to // true, the model will always follow the exact schema defined in the `schema` // field. Only a subset of JSON Schema is supported when `strict` is `true`. To @@ -3166,10 +3167,10 @@ type ResponseFormatTextJSONSchemaConfig struct { // Metadata for the response, check the presence of optional fields with the // [resp.Field.IsPresent] method. JSON struct { + Name resp.Field Schema resp.Field Type resp.Field Description resp.Field - Name resp.Field Strict resp.Field ExtraFields map[string]resp.Field raw string @@ -3196,8 +3197,11 @@ func (r ResponseFormatTextJSONSchemaConfig) ToParam() ResponseFormatTextJSONSche // more about // [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs). // -// The properties Schema, Type are required. +// The properties Name, Schema, Type are required. type ResponseFormatTextJSONSchemaConfigParam struct { + // The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores + // and dashes, with a maximum length of 64. + Name string `json:"name,required"` // The schema for the response format, described as a JSON Schema object. Learn how // to build JSON schemas [here](https://json-schema.org/). Schema map[string]interface{} `json:"schema,omitzero,required"` @@ -3210,9 +3214,6 @@ type ResponseFormatTextJSONSchemaConfigParam struct { // A description of what the response format is for, used by the model to determine // how to respond in the format. Description param.Opt[string] `json:"description,omitzero"` - // The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores - // and dashes, with a maximum length of 64. - Name param.Opt[string] `json:"name,omitzero"` // The type of response format being defined. Always `json_schema`. // // This field can be elided, and will marshal its zero value as "json_schema". @@ -7438,8 +7439,8 @@ type ResponseNewParams struct { // context. // // When using along with `previous_response_id`, the instructions from a previous - // response will be not be carried over to the next response. This makes it simple - // to swap out system (or developer) messages in new responses. + // response will not be carried over to the next response. This makes it simple to + // swap out system (or developer) messages in new responses. Instructions param.Opt[string] `json:"instructions,omitzero"` // An upper bound for the number of tokens that can be generated for a response, // including visible output tokens and