From 920756111c0f7725eb5746b22c1393e327dc2990 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:00:05 +0000 Subject: [PATCH] feat(api): new o1 and GPT-4o models + preference fine-tuning (#142) learn more here: https://platform.openai.com/docs/changelog --- .stats.yml | 2 +- api.md | 2 + chat.go | 71 +-- chatcompletion.go | 154 +++++-- chatcompletion_test.go | 7 +- client_test.go | 16 +- finetuningjob.go | 956 ++++++++++++++++++++++++++++++++++++++--- finetuningjob_test.go | 18 + shared/union.go | 25 +- usage_test.go | 2 +- 10 files changed, 1109 insertions(+), 144 deletions(-) diff --git a/.stats.yml b/.stats.yml index 3cc042f..d4d7d3c 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-2e0e0678be19d1118fd796af291822075e40538dba326611e177e9f3dc245a53.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-779ea2754025daf5e18eb8ceb203ec321692636bc3a999338556a479178efa6c.yml diff --git a/api.md b/api.md index 93ad03f..222385a 100644 --- a/api.md +++ b/api.md @@ -41,6 +41,7 @@ Params Types: - openai.ChatCompletionContentPartInputAudioParam - openai.ChatCompletionContentPartRefusalParam - openai.ChatCompletionContentPartTextParam +- openai.ChatCompletionDeveloperMessageParam - openai.ChatCompletionFunctionCallOptionParam - openai.ChatCompletionFunctionMessageParam - openai.ChatCompletionMessageParamUnion @@ -48,6 +49,7 @@ Params Types: - openai.ChatCompletionModality - openai.ChatCompletionNamedToolChoiceParam - openai.ChatCompletionPredictionContentParam +- openai.ChatCompletionReasoningEffort - openai.ChatCompletionStreamOptionsParam - openai.ChatCompletionSystemMessageParam - openai.ChatCompletionToolParam diff --git a/chat.go b/chat.go index b298e58..3e1d9dc 100644 --- a/chat.go +++ b/chat.go @@ -30,38 +30,41 @@ func NewChatService(opts ...option.RequestOption) (r *ChatService) { type ChatModel = string const ( - ChatModelO1Preview ChatModel = "o1-preview" - ChatModelO1Preview2024_09_12 ChatModel = "o1-preview-2024-09-12" - ChatModelO1Mini ChatModel = "o1-mini" - ChatModelO1Mini2024_09_12 ChatModel = "o1-mini-2024-09-12" - ChatModelGPT4o ChatModel = "gpt-4o" - ChatModelGPT4o2024_11_20 ChatModel = "gpt-4o-2024-11-20" - ChatModelGPT4o2024_08_06 ChatModel = "gpt-4o-2024-08-06" - ChatModelGPT4o2024_05_13 ChatModel = "gpt-4o-2024-05-13" - ChatModelGPT4oRealtimePreview ChatModel = "gpt-4o-realtime-preview" - ChatModelGPT4oRealtimePreview2024_10_01 ChatModel = "gpt-4o-realtime-preview-2024-10-01" - ChatModelGPT4oAudioPreview ChatModel = "gpt-4o-audio-preview" - ChatModelGPT4oAudioPreview2024_10_01 ChatModel = "gpt-4o-audio-preview-2024-10-01" - ChatModelChatgpt4oLatest ChatModel = "chatgpt-4o-latest" - ChatModelGPT4oMini ChatModel = "gpt-4o-mini" - ChatModelGPT4oMini2024_07_18 ChatModel = "gpt-4o-mini-2024-07-18" - ChatModelGPT4Turbo ChatModel = "gpt-4-turbo" - ChatModelGPT4Turbo2024_04_09 ChatModel = "gpt-4-turbo-2024-04-09" - ChatModelGPT4_0125Preview ChatModel = "gpt-4-0125-preview" - ChatModelGPT4TurboPreview ChatModel = "gpt-4-turbo-preview" - ChatModelGPT4_1106Preview ChatModel = "gpt-4-1106-preview" - ChatModelGPT4VisionPreview ChatModel = "gpt-4-vision-preview" - ChatModelGPT4 ChatModel = "gpt-4" - ChatModelGPT4_0314 ChatModel = "gpt-4-0314" - ChatModelGPT4_0613 ChatModel = "gpt-4-0613" - ChatModelGPT4_32k ChatModel = "gpt-4-32k" - ChatModelGPT4_32k0314 ChatModel = "gpt-4-32k-0314" - ChatModelGPT4_32k0613 ChatModel = "gpt-4-32k-0613" - ChatModelGPT3_5Turbo ChatModel = "gpt-3.5-turbo" - ChatModelGPT3_5Turbo16k ChatModel = "gpt-3.5-turbo-16k" - ChatModelGPT3_5Turbo0301 ChatModel = "gpt-3.5-turbo-0301" - ChatModelGPT3_5Turbo0613 ChatModel = "gpt-3.5-turbo-0613" - ChatModelGPT3_5Turbo1106 ChatModel = "gpt-3.5-turbo-1106" - ChatModelGPT3_5Turbo0125 ChatModel = "gpt-3.5-turbo-0125" - ChatModelGPT3_5Turbo16k0613 ChatModel = "gpt-3.5-turbo-16k-0613" + ChatModelO1 ChatModel = "o1" + ChatModelO1_2024_12_17 ChatModel = "o1-2024-12-17" + ChatModelO1Preview ChatModel = "o1-preview" + ChatModelO1Preview2024_09_12 ChatModel = "o1-preview-2024-09-12" + ChatModelO1Mini ChatModel = "o1-mini" + ChatModelO1Mini2024_09_12 ChatModel = "o1-mini-2024-09-12" + ChatModelGPT4o ChatModel = "gpt-4o" + ChatModelGPT4o2024_11_20 ChatModel = "gpt-4o-2024-11-20" + ChatModelGPT4o2024_08_06 ChatModel = "gpt-4o-2024-08-06" + ChatModelGPT4o2024_05_13 ChatModel = "gpt-4o-2024-05-13" + ChatModelGPT4oAudioPreview ChatModel = "gpt-4o-audio-preview" + ChatModelGPT4oAudioPreview2024_10_01 ChatModel = "gpt-4o-audio-preview-2024-10-01" + ChatModelGPT4oAudioPreview2024_12_17 ChatModel = "gpt-4o-audio-preview-2024-12-17" + ChatModelGPT4oMiniAudioPreview ChatModel = "gpt-4o-mini-audio-preview" + ChatModelGPT4oMiniAudioPreview2024_12_17 ChatModel = "gpt-4o-mini-audio-preview-2024-12-17" + ChatModelChatgpt4oLatest ChatModel = "chatgpt-4o-latest" + ChatModelGPT4oMini ChatModel = "gpt-4o-mini" + ChatModelGPT4oMini2024_07_18 ChatModel = "gpt-4o-mini-2024-07-18" + ChatModelGPT4Turbo ChatModel = "gpt-4-turbo" + ChatModelGPT4Turbo2024_04_09 ChatModel = "gpt-4-turbo-2024-04-09" + ChatModelGPT4_0125Preview ChatModel = "gpt-4-0125-preview" + ChatModelGPT4TurboPreview ChatModel = "gpt-4-turbo-preview" + ChatModelGPT4_1106Preview ChatModel = "gpt-4-1106-preview" + ChatModelGPT4VisionPreview ChatModel = "gpt-4-vision-preview" + ChatModelGPT4 ChatModel = "gpt-4" + ChatModelGPT4_0314 ChatModel = "gpt-4-0314" + ChatModelGPT4_0613 ChatModel = "gpt-4-0613" + ChatModelGPT4_32k ChatModel = "gpt-4-32k" + ChatModelGPT4_32k0314 ChatModel = "gpt-4-32k-0314" + ChatModelGPT4_32k0613 ChatModel = "gpt-4-32k-0613" + ChatModelGPT3_5Turbo ChatModel = "gpt-3.5-turbo" + ChatModelGPT3_5Turbo16k ChatModel = "gpt-3.5-turbo-16k" + ChatModelGPT3_5Turbo0301 ChatModel = "gpt-3.5-turbo-0301" + ChatModelGPT3_5Turbo0613 ChatModel = "gpt-3.5-turbo-0613" + ChatModelGPT3_5Turbo1106 ChatModel = "gpt-3.5-turbo-1106" + ChatModelGPT3_5Turbo0125 ChatModel = "gpt-3.5-turbo-0125" + ChatModelGPT3_5Turbo16k0613 ChatModel = "gpt-3.5-turbo-16k-0613" ) diff --git a/chatcompletion.go b/chatcompletion.go index 242776b..f00ba50 100644 --- a/chatcompletion.go +++ b/chatcompletion.go @@ -108,6 +108,12 @@ func NewChatCompletionService(opts ...option.RequestOption) (r *ChatCompletionSe // [text generation](https://platform.openai.com/docs/guides/text-generation), // [vision](https://platform.openai.com/docs/guides/vision), and // [audio](https://platform.openai.com/docs/guides/audio) guides. +// +// Parameter support can differ depending on the model used to generate the +// response, particularly for newer reasoning models. Parameters that are only +// supported for reasoning models are noted below. For the current state of +// unsupported parameters in reasoning models, +// [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning). func (r *ChatCompletionService) New(ctx context.Context, body ChatCompletionNewParams, opts ...option.RequestOption) (res *ChatCompletion, err error) { opts = append(r.Options[:], opts...) path := "chat/completions" @@ -119,6 +125,12 @@ func (r *ChatCompletionService) New(ctx context.Context, body ChatCompletionNewP // [text generation](https://platform.openai.com/docs/guides/text-generation), // [vision](https://platform.openai.com/docs/guides/vision), and // [audio](https://platform.openai.com/docs/guides/audio) guides. +// +// Parameter support can differ depending on the model used to generate the +// response, particularly for newer reasoning models. Parameters that are only +// supported for reasoning models are noted below. For the current state of +// unsupported parameters in reasoning models, +// [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning). func (r *ChatCompletionService) NewStreaming(ctx context.Context, body ChatCompletionNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[ChatCompletionChunk]) { var ( raw *http.Response @@ -298,6 +310,7 @@ func (r ChatCompletionServiceTier) IsKnown() bool { return false } +// Messages sent by the model in response to user messages. type ChatCompletionAssistantMessageParam struct { // The role of the messages author, in this case `assistant`. Role param.Field[ChatCompletionAssistantMessageParamRole] `json:"role,required"` @@ -1054,6 +1067,40 @@ func (r ChatCompletionContentPartTextType) IsKnown() bool { return false } +// Developer-provided instructions that the model should follow, regardless of +// messages sent by the user. With o1 models and newer, `developer` messages +// replace the previous `system` messages. +type ChatCompletionDeveloperMessageParam struct { + // The contents of the developer message. + Content param.Field[[]ChatCompletionContentPartTextParam] `json:"content,required"` + // The role of the messages author, in this case `developer`. + Role param.Field[ChatCompletionDeveloperMessageParamRole] `json:"role,required"` + // An optional name for the participant. Provides the model information to + // differentiate between participants of the same role. + Name param.Field[string] `json:"name"` +} + +func (r ChatCompletionDeveloperMessageParam) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +func (r ChatCompletionDeveloperMessageParam) implementsChatCompletionMessageParamUnion() {} + +// The role of the messages author, in this case `developer`. +type ChatCompletionDeveloperMessageParamRole string + +const ( + ChatCompletionDeveloperMessageParamRoleDeveloper ChatCompletionDeveloperMessageParamRole = "developer" +) + +func (r ChatCompletionDeveloperMessageParamRole) IsKnown() bool { + switch r { + case ChatCompletionDeveloperMessageParamRoleDeveloper: + return true + } + return false +} + // Specifying a particular function via `{"name": "my_function"}` forces the model // to call that function. type ChatCompletionFunctionCallOptionParam struct { @@ -1208,8 +1255,11 @@ func (r chatCompletionMessageFunctionCallJSON) RawJSON() string { return r.raw } +// Developer-provided instructions that the model should follow, regardless of +// messages sent by the user. With o1 models and newer, `developer` messages +// replace the previous `system` messages. type ChatCompletionMessageParam struct { - // The role of the messages author, in this case `system`. + // The role of the messages author, in this case `developer`. Role param.Field[ChatCompletionMessageParamRole] `json:"role,required"` Audio param.Field[interface{}] `json:"audio"` Content param.Field[interface{}] `json:"content"` @@ -1230,20 +1280,25 @@ func (r ChatCompletionMessageParam) MarshalJSON() (data []byte, err error) { func (r ChatCompletionMessageParam) implementsChatCompletionMessageParamUnion() {} -// Satisfied by [ChatCompletionSystemMessageParam], -// [ChatCompletionUserMessageParam], [ChatCompletionAssistantMessageParam], -// [ChatCompletionToolMessageParam], [ChatCompletionFunctionMessageParam], -// [ChatCompletionMessageParam]. +// Developer-provided instructions that the model should follow, regardless of +// messages sent by the user. With o1 models and newer, `developer` messages +// replace the previous `system` messages. +// +// Satisfied by [ChatCompletionDeveloperMessageParam], +// [ChatCompletionSystemMessageParam], [ChatCompletionUserMessageParam], +// [ChatCompletionAssistantMessageParam], [ChatCompletionToolMessageParam], +// [ChatCompletionFunctionMessageParam], [ChatCompletionMessageParam]. // // This union is additionally satisfied by the return types [ChatCompletionMessage] type ChatCompletionMessageParamUnion interface { implementsChatCompletionMessageParamUnion() } -// The role of the messages author, in this case `system`. +// The role of the messages author, in this case `developer`. type ChatCompletionMessageParamRole string const ( + ChatCompletionMessageParamRoleDeveloper ChatCompletionMessageParamRole = "developer" ChatCompletionMessageParamRoleSystem ChatCompletionMessageParamRole = "system" ChatCompletionMessageParamRoleUser ChatCompletionMessageParamRole = "user" ChatCompletionMessageParamRoleAssistant ChatCompletionMessageParamRole = "assistant" @@ -1253,7 +1308,7 @@ const ( func (r ChatCompletionMessageParamRole) IsKnown() bool { switch r { - case ChatCompletionMessageParamRoleSystem, ChatCompletionMessageParamRoleUser, ChatCompletionMessageParamRoleAssistant, ChatCompletionMessageParamRoleTool, ChatCompletionMessageParamRoleFunction: + case ChatCompletionMessageParamRoleDeveloper, ChatCompletionMessageParamRoleSystem, ChatCompletionMessageParamRoleUser, ChatCompletionMessageParamRoleAssistant, ChatCompletionMessageParamRoleTool, ChatCompletionMessageParamRoleFunction: return true } return false @@ -1444,6 +1499,28 @@ func (r ChatCompletionPredictionContentType) IsKnown() bool { return false } +// **o1 models only** +// +// Constrains effort on reasoning for +// [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently +// supported values are `low`, `medium`, and `high`. Reducing reasoning effort can +// result in faster responses and fewer tokens used on reasoning in a response. +type ChatCompletionReasoningEffort string + +const ( + ChatCompletionReasoningEffortLow ChatCompletionReasoningEffort = "low" + ChatCompletionReasoningEffortMedium ChatCompletionReasoningEffort = "medium" + ChatCompletionReasoningEffortHigh ChatCompletionReasoningEffort = "high" +) + +func (r ChatCompletionReasoningEffort) IsKnown() bool { + switch r { + case ChatCompletionReasoningEffortLow, ChatCompletionReasoningEffortMedium, ChatCompletionReasoningEffortHigh: + return true + } + return false +} + // Options for streaming response. Only set this when you set `stream: true`. type ChatCompletionStreamOptionsParam struct { // If set, an additional chunk will be streamed before the `data: [DONE]` message. @@ -1457,6 +1534,9 @@ func (r ChatCompletionStreamOptionsParam) MarshalJSON() (data []byte, err error) return apijson.MarshalRoot(r) } +// Developer-provided instructions that the model should follow, regardless of +// messages sent by the user. With o1 models and newer, use `developer` messages +// for this purpose instead. type ChatCompletionSystemMessageParam struct { // The contents of the system message. Content param.Field[[]ChatCompletionContentPartTextParam] `json:"content,required"` @@ -1652,6 +1732,8 @@ func (r ChatCompletionToolMessageParamRole) IsKnown() bool { return false } +// Messages sent by an end user, containing prompts or additional context +// information. type ChatCompletionUserMessageParam struct { // The contents of the user message. Content param.Field[[]ChatCompletionContentPartUnionParam] `json:"content,required"` @@ -1702,17 +1784,19 @@ type ChatCompletionNewParams struct { // Number between -2.0 and 2.0. Positive values penalize new tokens based on their // existing frequency in the text so far, decreasing the model's likelihood to // repeat the same line verbatim. - // - // [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation) FrequencyPenalty param.Field[float64] `json:"frequency_penalty"` // Deprecated in favor of `tool_choice`. // - // Controls which (if any) function is called by the model. `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. Specifying a - // particular function via `{"name": "my_function"}` forces the model to call that + // Controls which (if any) function is called by the model. + // + // `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. // + // Specifying a particular function via `{"name": "my_function"}` forces the model + // to call that function. + // // `none` is the default when no functions are present. `auto` is the default if // functions are present. FunctionCall param.Field[ChatCompletionNewParamsFunctionCallUnion] `json:"function_call"` @@ -1773,14 +1857,15 @@ type ChatCompletionNewParams struct { // Number between -2.0 and 2.0. Positive values penalize new tokens based on // whether they appear in the text so far, increasing the model's likelihood to // talk about new topics. - // - // [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation) PresencePenalty param.Field[float64] `json:"presence_penalty"` - // An object specifying the format that the model must output. Compatible with - // [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), - // [GPT-4o mini](https://platform.openai.com/docs/models#gpt-4o-mini), - // [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4) and - // all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. + // **o1 models only** + // + // Constrains effort on reasoning for + // [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently + // supported values are `low`, `medium`, and `high`. Reducing reasoning effort can + // result in faster responses and fewer tokens used on reasoning in a response. + ReasoningEffort param.Field[ChatCompletionReasoningEffort] `json:"reasoning_effort"` + // An object specifying the format that the model must output. // // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured // Outputs which ensures the model will match your supplied JSON schema. Learn more @@ -1829,9 +1914,8 @@ type ChatCompletionNewParams struct { StreamOptions param.Field[ChatCompletionStreamOptionsParam] `json:"stream_options"` // What sampling temperature to use, between 0 and 2. Higher values like 0.8 will // make the output more random, while lower values like 0.2 will make it more - // focused and deterministic. - // - // We generally recommend altering this or `top_p` but not both. + // focused and deterministic. We generally recommend altering this or `top_p` but + // not both. Temperature param.Field[float64] `json:"temperature"` // Controls which (if any) tool is called by the model. `none` means the model will // not call any tool and instead generates a message. `auto` means the model can @@ -1869,12 +1953,16 @@ func (r ChatCompletionNewParams) MarshalJSON() (data []byte, err error) { // Deprecated in favor of `tool_choice`. // -// Controls which (if any) function is called by the model. `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. Specifying a -// particular function via `{"name": "my_function"}` forces the model to call that +// Controls which (if any) function is called by the model. +// +// `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. // +// Specifying a particular function via `{"name": "my_function"}` forces the model +// to call that function. +// // `none` is the default when no functions are present. `auto` is the default if // functions are present. // @@ -1926,11 +2014,7 @@ func (r ChatCompletionNewParamsFunction) MarshalJSON() (data []byte, err error) return apijson.MarshalRoot(r) } -// An object specifying the format that the model must output. Compatible with -// [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), -// [GPT-4o mini](https://platform.openai.com/docs/models#gpt-4o-mini), -// [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4) and -// all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. +// An object specifying the format that the model must output. // // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured // Outputs which ensures the model will match your supplied JSON schema. Learn more @@ -1960,11 +2044,7 @@ func (r ChatCompletionNewParamsResponseFormat) MarshalJSON() (data []byte, err e func (r ChatCompletionNewParamsResponseFormat) ImplementsChatCompletionNewParamsResponseFormatUnion() { } -// An object specifying the format that the model must output. Compatible with -// [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), -// [GPT-4o mini](https://platform.openai.com/docs/models#gpt-4o-mini), -// [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4) and -// all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. +// An object specifying the format that the model must output. // // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured // Outputs which ensures the model will match your supplied JSON schema. Learn more diff --git a/chatcompletion_test.go b/chatcompletion_test.go index 7789b73..8a91514 100644 --- a/chatcompletion_test.go +++ b/chatcompletion_test.go @@ -27,12 +27,12 @@ func TestChatCompletionNewWithOptionalParams(t *testing.T) { option.WithAPIKey("My API Key"), ) _, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{ - Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionSystemMessageParam{ + Messages: openai.F([]openai.ChatCompletionMessageParamUnion{openai.ChatCompletionDeveloperMessageParam{ Content: openai.F([]openai.ChatCompletionContentPartTextParam{{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), - Role: openai.F(openai.ChatCompletionSystemMessageParamRoleSystem), + Role: openai.F(openai.ChatCompletionDeveloperMessageParamRoleDeveloper), Name: openai.F("name"), }}), - Model: openai.F(openai.ChatModelO1Preview), + Model: openai.F(openai.ChatModelO1), Audio: openai.F(openai.ChatCompletionAudioParam{ Format: openai.F(openai.ChatCompletionAudioParamFormatWAV), Voice: openai.F(openai.ChatCompletionAudioParamVoiceAlloy), @@ -63,6 +63,7 @@ func TestChatCompletionNewWithOptionalParams(t *testing.T) { Type: openai.F(openai.ChatCompletionPredictionContentTypeContent), }), PresencePenalty: openai.F(-2.000000), + ReasoningEffort: openai.F(openai.ChatCompletionReasoningEffortLow), ResponseFormat: openai.F[openai.ChatCompletionNewParamsResponseFormatUnion](shared.ResponseFormatTextParam{ Type: openai.F(shared.ResponseFormatTextTypeText), }), diff --git a/client_test.go b/client_test.go index eb8adac..98d28e7 100644 --- a/client_test.go +++ b/client_test.go @@ -42,7 +42,7 @@ func TestUserAgentHeader(t *testing.T) { Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), - Model: openai.F(openai.ChatModelO1Preview), + Model: openai.F(openai.ChatModelO1), }) if userAgent != fmt.Sprintf("OpenAI/Go %s", internal.PackageVersion) { t.Errorf("Expected User-Agent to be correct, but got: %#v", userAgent) @@ -71,7 +71,7 @@ func TestRetryAfter(t *testing.T) { Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), - Model: openai.F(openai.ChatModelO1Preview), + Model: openai.F(openai.ChatModelO1), }) if err == nil || res != nil { t.Error("Expected there to be a cancel error and for the response to be nil") @@ -111,7 +111,7 @@ func TestDeleteRetryCountHeader(t *testing.T) { Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), - Model: openai.F(openai.ChatModelO1Preview), + Model: openai.F(openai.ChatModelO1), }) if err == nil || res != nil { t.Error("Expected there to be a cancel error and for the response to be nil") @@ -146,7 +146,7 @@ func TestOverwriteRetryCountHeader(t *testing.T) { Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), - Model: openai.F(openai.ChatModelO1Preview), + Model: openai.F(openai.ChatModelO1), }) if err == nil || res != nil { t.Error("Expected there to be a cancel error and for the response to be nil") @@ -180,7 +180,7 @@ func TestRetryAfterMs(t *testing.T) { Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), - Model: openai.F(openai.ChatModelO1Preview), + Model: openai.F(openai.ChatModelO1), }) if err == nil || res != nil { t.Error("Expected there to be a cancel error and for the response to be nil") @@ -208,7 +208,7 @@ func TestContextCancel(t *testing.T) { Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), - Model: openai.F(openai.ChatModelO1Preview), + Model: openai.F(openai.ChatModelO1), }) if err == nil || res != nil { t.Error("Expected there to be a cancel error and for the response to be nil") @@ -233,7 +233,7 @@ func TestContextCancelDelay(t *testing.T) { Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), - Model: openai.F(openai.ChatModelO1Preview), + Model: openai.F(openai.ChatModelO1), }) if err == nil || res != nil { t.Error("expected there to be a cancel error and for the response to be nil") @@ -264,7 +264,7 @@ func TestContextDeadline(t *testing.T) { Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), - Model: openai.F(openai.ChatModelO1Preview), + Model: openai.F(openai.ChatModelO1), }) if err == nil || res != nil { t.Error("expected there to be a deadline error and for the response to be nil") diff --git a/finetuningjob.go b/finetuningjob.go index d3101eb..6384c6a 100644 --- a/finetuningjob.go +++ b/finetuningjob.go @@ -147,9 +147,8 @@ type FineTuningJob struct { // The Unix timestamp (in seconds) for when the fine-tuning job was finished. The // value will be null if the fine-tuning job is still running. FinishedAt int64 `json:"finished_at,required,nullable"` - // The hyperparameters used for the fine-tuning job. See the - // [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning) for - // more details. + // The hyperparameters used for the fine-tuning job. This value will only be + // returned when running `supervised` jobs. Hyperparameters FineTuningJobHyperparameters `json:"hyperparameters,required"` // The base model that is being fine-tuned. Model string `json:"model,required"` @@ -181,7 +180,9 @@ type FineTuningJob struct { EstimatedFinish int64 `json:"estimated_finish,nullable"` // A list of integrations to enable for this fine-tuning job. Integrations []FineTuningJobWandbIntegrationObject `json:"integrations,nullable"` - JSON fineTuningJobJSON `json:"-"` + // The method used for fine-tuning. + Method FineTuningJobMethod `json:"method"` + JSON fineTuningJobJSON `json:"-"` } // fineTuningJobJSON contains the JSON metadata for the struct [FineTuningJob] @@ -203,6 +204,7 @@ type fineTuningJobJSON struct { ValidationFile apijson.Field EstimatedFinish apijson.Field Integrations apijson.Field + Method apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -246,108 +248,641 @@ func (r fineTuningJobErrorJSON) RawJSON() string { return r.raw } -// The hyperparameters used for the fine-tuning job. See the -// [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning) for -// more details. +// The hyperparameters used for the fine-tuning job. This value will only be +// returned when running `supervised` jobs. type FineTuningJobHyperparameters struct { + // Number of examples in each batch. A larger batch size means that model + // parameters are updated less frequently, but with lower variance. + BatchSize FineTuningJobHyperparametersBatchSizeUnion `json:"batch_size"` + // Scaling factor for the learning rate. A smaller learning rate may be useful to + // avoid overfitting. + LearningRateMultiplier FineTuningJobHyperparametersLearningRateMultiplierUnion `json:"learning_rate_multiplier"` // The number of epochs to train the model for. An epoch refers to one full cycle - // through the training dataset. "auto" decides the optimal number of epochs based - // on the size of the dataset. If setting the number manually, we support any - // number between 1 and 50 epochs. - NEpochs FineTuningJobHyperparametersNEpochsUnion `json:"n_epochs,required"` + // through the training dataset. + NEpochs FineTuningJobHyperparametersNEpochsUnion `json:"n_epochs"` JSON fineTuningJobHyperparametersJSON `json:"-"` } // fineTuningJobHyperparametersJSON contains the JSON metadata for the struct // [FineTuningJobHyperparameters] type fineTuningJobHyperparametersJSON struct { - NEpochs apijson.Field + BatchSize apijson.Field + LearningRateMultiplier apijson.Field + NEpochs apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *FineTuningJobHyperparameters) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r fineTuningJobHyperparametersJSON) RawJSON() string { + return r.raw +} + +// Number of examples in each batch. A larger batch size means that model +// parameters are updated less frequently, but with lower variance. +// +// Union satisfied by [FineTuningJobHyperparametersBatchSizeAuto] or +// [shared.UnionInt]. +type FineTuningJobHyperparametersBatchSizeUnion interface { + ImplementsFineTuningJobHyperparametersBatchSizeUnion() +} + +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*FineTuningJobHyperparametersBatchSizeUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(FineTuningJobHyperparametersBatchSizeAuto("")), + }, + apijson.UnionVariant{ + TypeFilter: gjson.Number, + Type: reflect.TypeOf(shared.UnionInt(0)), + }, + ) +} + +type FineTuningJobHyperparametersBatchSizeAuto string + +const ( + FineTuningJobHyperparametersBatchSizeAutoAuto FineTuningJobHyperparametersBatchSizeAuto = "auto" +) + +func (r FineTuningJobHyperparametersBatchSizeAuto) IsKnown() bool { + switch r { + case FineTuningJobHyperparametersBatchSizeAutoAuto: + return true + } + return false +} + +func (r FineTuningJobHyperparametersBatchSizeAuto) ImplementsFineTuningJobHyperparametersBatchSizeUnion() { +} + +// Scaling factor for the learning rate. A smaller learning rate may be useful to +// avoid overfitting. +// +// Union satisfied by [FineTuningJobHyperparametersLearningRateMultiplierAuto] or +// [shared.UnionFloat]. +type FineTuningJobHyperparametersLearningRateMultiplierUnion interface { + ImplementsFineTuningJobHyperparametersLearningRateMultiplierUnion() +} + +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*FineTuningJobHyperparametersLearningRateMultiplierUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(FineTuningJobHyperparametersLearningRateMultiplierAuto("")), + }, + apijson.UnionVariant{ + TypeFilter: gjson.Number, + Type: reflect.TypeOf(shared.UnionFloat(0)), + }, + ) +} + +type FineTuningJobHyperparametersLearningRateMultiplierAuto string + +const ( + FineTuningJobHyperparametersLearningRateMultiplierAutoAuto FineTuningJobHyperparametersLearningRateMultiplierAuto = "auto" +) + +func (r FineTuningJobHyperparametersLearningRateMultiplierAuto) IsKnown() bool { + switch r { + case FineTuningJobHyperparametersLearningRateMultiplierAutoAuto: + return true + } + return false +} + +func (r FineTuningJobHyperparametersLearningRateMultiplierAuto) ImplementsFineTuningJobHyperparametersLearningRateMultiplierUnion() { +} + +// The number of epochs to train the model for. An epoch refers to one full cycle +// through the training dataset. +// +// Union satisfied by [FineTuningJobHyperparametersNEpochsBehavior] or +// [shared.UnionInt]. +type FineTuningJobHyperparametersNEpochsUnion interface { + ImplementsFineTuningJobHyperparametersNEpochsUnion() +} + +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*FineTuningJobHyperparametersNEpochsUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(FineTuningJobHyperparametersNEpochsBehavior("")), + }, + apijson.UnionVariant{ + TypeFilter: gjson.Number, + Type: reflect.TypeOf(shared.UnionInt(0)), + }, + ) +} + +type FineTuningJobHyperparametersNEpochsBehavior string + +const ( + FineTuningJobHyperparametersNEpochsBehaviorAuto FineTuningJobHyperparametersNEpochsBehavior = "auto" +) + +func (r FineTuningJobHyperparametersNEpochsBehavior) IsKnown() bool { + switch r { + case FineTuningJobHyperparametersNEpochsBehaviorAuto: + return true + } + return false +} + +func (r FineTuningJobHyperparametersNEpochsBehavior) ImplementsFineTuningJobHyperparametersNEpochsUnion() { +} + +// The object type, which is always "fine_tuning.job". +type FineTuningJobObject string + +const ( + FineTuningJobObjectFineTuningJob FineTuningJobObject = "fine_tuning.job" +) + +func (r FineTuningJobObject) IsKnown() bool { + switch r { + case FineTuningJobObjectFineTuningJob: + return true + } + return false +} + +// The current status of the fine-tuning job, which can be either +// `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`. +type FineTuningJobStatus string + +const ( + FineTuningJobStatusValidatingFiles FineTuningJobStatus = "validating_files" + FineTuningJobStatusQueued FineTuningJobStatus = "queued" + FineTuningJobStatusRunning FineTuningJobStatus = "running" + FineTuningJobStatusSucceeded FineTuningJobStatus = "succeeded" + FineTuningJobStatusFailed FineTuningJobStatus = "failed" + FineTuningJobStatusCancelled FineTuningJobStatus = "cancelled" +) + +func (r FineTuningJobStatus) IsKnown() bool { + switch r { + case FineTuningJobStatusValidatingFiles, FineTuningJobStatusQueued, FineTuningJobStatusRunning, FineTuningJobStatusSucceeded, FineTuningJobStatusFailed, FineTuningJobStatusCancelled: + return true + } + return false +} + +// The method used for fine-tuning. +type FineTuningJobMethod struct { + // Configuration for the DPO fine-tuning method. + Dpo FineTuningJobMethodDpo `json:"dpo"` + // Configuration for the supervised fine-tuning method. + Supervised FineTuningJobMethodSupervised `json:"supervised"` + // The type of method. Is either `supervised` or `dpo`. + Type FineTuningJobMethodType `json:"type"` + JSON fineTuningJobMethodJSON `json:"-"` +} + +// fineTuningJobMethodJSON contains the JSON metadata for the struct +// [FineTuningJobMethod] +type fineTuningJobMethodJSON struct { + Dpo apijson.Field + Supervised apijson.Field + Type apijson.Field raw string ExtraFields map[string]apijson.Field } -func (r *FineTuningJobHyperparameters) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) +func (r *FineTuningJobMethod) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r fineTuningJobMethodJSON) RawJSON() string { + return r.raw +} + +// Configuration for the DPO fine-tuning method. +type FineTuningJobMethodDpo struct { + // The hyperparameters used for the fine-tuning job. + Hyperparameters FineTuningJobMethodDpoHyperparameters `json:"hyperparameters"` + JSON fineTuningJobMethodDpoJSON `json:"-"` +} + +// fineTuningJobMethodDpoJSON contains the JSON metadata for the struct +// [FineTuningJobMethodDpo] +type fineTuningJobMethodDpoJSON struct { + Hyperparameters apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *FineTuningJobMethodDpo) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r fineTuningJobMethodDpoJSON) RawJSON() string { + return r.raw +} + +// The hyperparameters used for the fine-tuning job. +type FineTuningJobMethodDpoHyperparameters struct { + // Number of examples in each batch. A larger batch size means that model + // parameters are updated less frequently, but with lower variance. + BatchSize FineTuningJobMethodDpoHyperparametersBatchSizeUnion `json:"batch_size"` + // The beta value for the DPO method. A higher beta value will increase the weight + // of the penalty between the policy and reference model. + Beta FineTuningJobMethodDpoHyperparametersBetaUnion `json:"beta"` + // Scaling factor for the learning rate. A smaller learning rate may be useful to + // avoid overfitting. + LearningRateMultiplier FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion `json:"learning_rate_multiplier"` + // The number of epochs to train the model for. An epoch refers to one full cycle + // through the training dataset. + NEpochs FineTuningJobMethodDpoHyperparametersNEpochsUnion `json:"n_epochs"` + JSON fineTuningJobMethodDpoHyperparametersJSON `json:"-"` +} + +// fineTuningJobMethodDpoHyperparametersJSON contains the JSON metadata for the +// struct [FineTuningJobMethodDpoHyperparameters] +type fineTuningJobMethodDpoHyperparametersJSON struct { + BatchSize apijson.Field + Beta apijson.Field + LearningRateMultiplier apijson.Field + NEpochs apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *FineTuningJobMethodDpoHyperparameters) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r fineTuningJobMethodDpoHyperparametersJSON) RawJSON() string { + return r.raw +} + +// Number of examples in each batch. A larger batch size means that model +// parameters are updated less frequently, but with lower variance. +// +// Union satisfied by [FineTuningJobMethodDpoHyperparametersBatchSizeAuto] or +// [shared.UnionInt]. +type FineTuningJobMethodDpoHyperparametersBatchSizeUnion interface { + ImplementsFineTuningJobMethodDpoHyperparametersBatchSizeUnion() +} + +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*FineTuningJobMethodDpoHyperparametersBatchSizeUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(FineTuningJobMethodDpoHyperparametersBatchSizeAuto("")), + }, + apijson.UnionVariant{ + TypeFilter: gjson.Number, + Type: reflect.TypeOf(shared.UnionInt(0)), + }, + ) +} + +type FineTuningJobMethodDpoHyperparametersBatchSizeAuto string + +const ( + FineTuningJobMethodDpoHyperparametersBatchSizeAutoAuto FineTuningJobMethodDpoHyperparametersBatchSizeAuto = "auto" +) + +func (r FineTuningJobMethodDpoHyperparametersBatchSizeAuto) IsKnown() bool { + switch r { + case FineTuningJobMethodDpoHyperparametersBatchSizeAutoAuto: + return true + } + return false +} + +func (r FineTuningJobMethodDpoHyperparametersBatchSizeAuto) ImplementsFineTuningJobMethodDpoHyperparametersBatchSizeUnion() { +} + +// The beta value for the DPO method. A higher beta value will increase the weight +// of the penalty between the policy and reference model. +// +// Union satisfied by [FineTuningJobMethodDpoHyperparametersBetaAuto] or +// [shared.UnionFloat]. +type FineTuningJobMethodDpoHyperparametersBetaUnion interface { + ImplementsFineTuningJobMethodDpoHyperparametersBetaUnion() +} + +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*FineTuningJobMethodDpoHyperparametersBetaUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(FineTuningJobMethodDpoHyperparametersBetaAuto("")), + }, + apijson.UnionVariant{ + TypeFilter: gjson.Number, + Type: reflect.TypeOf(shared.UnionFloat(0)), + }, + ) +} + +type FineTuningJobMethodDpoHyperparametersBetaAuto string + +const ( + FineTuningJobMethodDpoHyperparametersBetaAutoAuto FineTuningJobMethodDpoHyperparametersBetaAuto = "auto" +) + +func (r FineTuningJobMethodDpoHyperparametersBetaAuto) IsKnown() bool { + switch r { + case FineTuningJobMethodDpoHyperparametersBetaAutoAuto: + return true + } + return false +} + +func (r FineTuningJobMethodDpoHyperparametersBetaAuto) ImplementsFineTuningJobMethodDpoHyperparametersBetaUnion() { +} + +// Scaling factor for the learning rate. A smaller learning rate may be useful to +// avoid overfitting. +// +// Union satisfied by +// [FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto] or +// [shared.UnionFloat]. +type FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion interface { + ImplementsFineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion() +} + +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto("")), + }, + apijson.UnionVariant{ + TypeFilter: gjson.Number, + Type: reflect.TypeOf(shared.UnionFloat(0)), + }, + ) +} + +type FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto string + +const ( + FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAutoAuto FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto = "auto" +) + +func (r FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto) IsKnown() bool { + switch r { + case FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAutoAuto: + return true + } + return false +} + +func (r FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto) ImplementsFineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion() { +} + +// The number of epochs to train the model for. An epoch refers to one full cycle +// through the training dataset. +// +// Union satisfied by [FineTuningJobMethodDpoHyperparametersNEpochsAuto] or +// [shared.UnionInt]. +type FineTuningJobMethodDpoHyperparametersNEpochsUnion interface { + ImplementsFineTuningJobMethodDpoHyperparametersNEpochsUnion() +} + +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*FineTuningJobMethodDpoHyperparametersNEpochsUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(FineTuningJobMethodDpoHyperparametersNEpochsAuto("")), + }, + apijson.UnionVariant{ + TypeFilter: gjson.Number, + Type: reflect.TypeOf(shared.UnionInt(0)), + }, + ) +} + +type FineTuningJobMethodDpoHyperparametersNEpochsAuto string + +const ( + FineTuningJobMethodDpoHyperparametersNEpochsAutoAuto FineTuningJobMethodDpoHyperparametersNEpochsAuto = "auto" +) + +func (r FineTuningJobMethodDpoHyperparametersNEpochsAuto) IsKnown() bool { + switch r { + case FineTuningJobMethodDpoHyperparametersNEpochsAutoAuto: + return true + } + return false +} + +func (r FineTuningJobMethodDpoHyperparametersNEpochsAuto) ImplementsFineTuningJobMethodDpoHyperparametersNEpochsUnion() { +} + +// Configuration for the supervised fine-tuning method. +type FineTuningJobMethodSupervised struct { + // The hyperparameters used for the fine-tuning job. + Hyperparameters FineTuningJobMethodSupervisedHyperparameters `json:"hyperparameters"` + JSON fineTuningJobMethodSupervisedJSON `json:"-"` +} + +// fineTuningJobMethodSupervisedJSON contains the JSON metadata for the struct +// [FineTuningJobMethodSupervised] +type fineTuningJobMethodSupervisedJSON struct { + Hyperparameters apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *FineTuningJobMethodSupervised) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r fineTuningJobMethodSupervisedJSON) RawJSON() string { + return r.raw +} + +// The hyperparameters used for the fine-tuning job. +type FineTuningJobMethodSupervisedHyperparameters struct { + // Number of examples in each batch. A larger batch size means that model + // parameters are updated less frequently, but with lower variance. + BatchSize FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion `json:"batch_size"` + // Scaling factor for the learning rate. A smaller learning rate may be useful to + // avoid overfitting. + LearningRateMultiplier FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion `json:"learning_rate_multiplier"` + // The number of epochs to train the model for. An epoch refers to one full cycle + // through the training dataset. + NEpochs FineTuningJobMethodSupervisedHyperparametersNEpochsUnion `json:"n_epochs"` + JSON fineTuningJobMethodSupervisedHyperparametersJSON `json:"-"` +} + +// fineTuningJobMethodSupervisedHyperparametersJSON contains the JSON metadata for +// the struct [FineTuningJobMethodSupervisedHyperparameters] +type fineTuningJobMethodSupervisedHyperparametersJSON struct { + BatchSize apijson.Field + LearningRateMultiplier apijson.Field + NEpochs apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *FineTuningJobMethodSupervisedHyperparameters) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r fineTuningJobMethodSupervisedHyperparametersJSON) RawJSON() string { + return r.raw +} + +// Number of examples in each batch. A larger batch size means that model +// parameters are updated less frequently, but with lower variance. +// +// Union satisfied by [FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto] +// or [shared.UnionInt]. +type FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion interface { + ImplementsFineTuningJobMethodSupervisedHyperparametersBatchSizeUnion() +} + +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto("")), + }, + apijson.UnionVariant{ + TypeFilter: gjson.Number, + Type: reflect.TypeOf(shared.UnionInt(0)), + }, + ) +} + +type FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto string + +const ( + FineTuningJobMethodSupervisedHyperparametersBatchSizeAutoAuto FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto = "auto" +) + +func (r FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto) IsKnown() bool { + switch r { + case FineTuningJobMethodSupervisedHyperparametersBatchSizeAutoAuto: + return true + } + return false } -func (r fineTuningJobHyperparametersJSON) RawJSON() string { - return r.raw +func (r FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto) ImplementsFineTuningJobMethodSupervisedHyperparametersBatchSizeUnion() { } -// The number of epochs to train the model for. An epoch refers to one full cycle -// through the training dataset. "auto" decides the optimal number of epochs based -// on the size of the dataset. If setting the number manually, we support any -// number between 1 and 50 epochs. +// Scaling factor for the learning rate. A smaller learning rate may be useful to +// avoid overfitting. // -// Union satisfied by [FineTuningJobHyperparametersNEpochsBehavior] or -// [shared.UnionInt]. -type FineTuningJobHyperparametersNEpochsUnion interface { - ImplementsFineTuningJobHyperparametersNEpochsUnion() +// Union satisfied by +// [FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto] or +// [shared.UnionFloat]. +type FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion interface { + ImplementsFineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion() } func init() { apijson.RegisterUnion( - reflect.TypeOf((*FineTuningJobHyperparametersNEpochsUnion)(nil)).Elem(), + reflect.TypeOf((*FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion)(nil)).Elem(), "", apijson.UnionVariant{ TypeFilter: gjson.String, - Type: reflect.TypeOf(FineTuningJobHyperparametersNEpochsBehavior("")), + Type: reflect.TypeOf(FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto("")), }, apijson.UnionVariant{ TypeFilter: gjson.Number, - Type: reflect.TypeOf(shared.UnionInt(0)), + Type: reflect.TypeOf(shared.UnionFloat(0)), }, ) } -type FineTuningJobHyperparametersNEpochsBehavior string +type FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto string const ( - FineTuningJobHyperparametersNEpochsBehaviorAuto FineTuningJobHyperparametersNEpochsBehavior = "auto" + FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAutoAuto FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto = "auto" ) -func (r FineTuningJobHyperparametersNEpochsBehavior) IsKnown() bool { +func (r FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto) IsKnown() bool { switch r { - case FineTuningJobHyperparametersNEpochsBehaviorAuto: + case FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAutoAuto: return true } return false } -func (r FineTuningJobHyperparametersNEpochsBehavior) ImplementsFineTuningJobHyperparametersNEpochsUnion() { +func (r FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto) ImplementsFineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion() { } -// The object type, which is always "fine_tuning.job". -type FineTuningJobObject string +// The number of epochs to train the model for. An epoch refers to one full cycle +// through the training dataset. +// +// Union satisfied by [FineTuningJobMethodSupervisedHyperparametersNEpochsAuto] or +// [shared.UnionInt]. +type FineTuningJobMethodSupervisedHyperparametersNEpochsUnion interface { + ImplementsFineTuningJobMethodSupervisedHyperparametersNEpochsUnion() +} + +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*FineTuningJobMethodSupervisedHyperparametersNEpochsUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(FineTuningJobMethodSupervisedHyperparametersNEpochsAuto("")), + }, + apijson.UnionVariant{ + TypeFilter: gjson.Number, + Type: reflect.TypeOf(shared.UnionInt(0)), + }, + ) +} + +type FineTuningJobMethodSupervisedHyperparametersNEpochsAuto string const ( - FineTuningJobObjectFineTuningJob FineTuningJobObject = "fine_tuning.job" + FineTuningJobMethodSupervisedHyperparametersNEpochsAutoAuto FineTuningJobMethodSupervisedHyperparametersNEpochsAuto = "auto" ) -func (r FineTuningJobObject) IsKnown() bool { +func (r FineTuningJobMethodSupervisedHyperparametersNEpochsAuto) IsKnown() bool { switch r { - case FineTuningJobObjectFineTuningJob: + case FineTuningJobMethodSupervisedHyperparametersNEpochsAutoAuto: return true } return false } -// The current status of the fine-tuning job, which can be either -// `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`. -type FineTuningJobStatus string +func (r FineTuningJobMethodSupervisedHyperparametersNEpochsAuto) ImplementsFineTuningJobMethodSupervisedHyperparametersNEpochsUnion() { +} + +// The type of method. Is either `supervised` or `dpo`. +type FineTuningJobMethodType string const ( - FineTuningJobStatusValidatingFiles FineTuningJobStatus = "validating_files" - FineTuningJobStatusQueued FineTuningJobStatus = "queued" - FineTuningJobStatusRunning FineTuningJobStatus = "running" - FineTuningJobStatusSucceeded FineTuningJobStatus = "succeeded" - FineTuningJobStatusFailed FineTuningJobStatus = "failed" - FineTuningJobStatusCancelled FineTuningJobStatus = "cancelled" + FineTuningJobMethodTypeSupervised FineTuningJobMethodType = "supervised" + FineTuningJobMethodTypeDpo FineTuningJobMethodType = "dpo" ) -func (r FineTuningJobStatus) IsKnown() bool { +func (r FineTuningJobMethodType) IsKnown() bool { switch r { - case FineTuningJobStatusValidatingFiles, FineTuningJobStatusQueued, FineTuningJobStatusRunning, FineTuningJobStatusSucceeded, FineTuningJobStatusFailed, FineTuningJobStatusCancelled: + case FineTuningJobMethodTypeSupervised, FineTuningJobMethodTypeDpo: return true } return false @@ -355,12 +890,21 @@ func (r FineTuningJobStatus) IsKnown() bool { // Fine-tuning job event object type FineTuningJobEvent struct { - ID string `json:"id,required"` - CreatedAt int64 `json:"created_at,required"` - Level FineTuningJobEventLevel `json:"level,required"` - Message string `json:"message,required"` - Object FineTuningJobEventObject `json:"object,required"` - JSON fineTuningJobEventJSON `json:"-"` + // The object identifier. + ID string `json:"id,required"` + // The Unix timestamp (in seconds) for when the fine-tuning job was created. + CreatedAt int64 `json:"created_at,required"` + // The log level of the event. + Level FineTuningJobEventLevel `json:"level,required"` + // The message of the event. + Message string `json:"message,required"` + // The object type, which is always "fine_tuning.job.event". + Object FineTuningJobEventObject `json:"object,required"` + // The data associated with the event. + Data interface{} `json:"data"` + // The type of event. + Type FineTuningJobEventType `json:"type"` + JSON fineTuningJobEventJSON `json:"-"` } // fineTuningJobEventJSON contains the JSON metadata for the struct @@ -371,6 +915,8 @@ type fineTuningJobEventJSON struct { Level apijson.Field Message apijson.Field Object apijson.Field + Data apijson.Field + Type apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -383,6 +929,7 @@ func (r fineTuningJobEventJSON) RawJSON() string { return r.raw } +// The log level of the event. type FineTuningJobEventLevel string const ( @@ -399,6 +946,7 @@ func (r FineTuningJobEventLevel) IsKnown() bool { return false } +// The object type, which is always "fine_tuning.job.event". type FineTuningJobEventObject string const ( @@ -413,6 +961,22 @@ func (r FineTuningJobEventObject) IsKnown() bool { return false } +// The type of event. +type FineTuningJobEventType string + +const ( + FineTuningJobEventTypeMessage FineTuningJobEventType = "message" + FineTuningJobEventTypeMetrics FineTuningJobEventType = "metrics" +) + +func (r FineTuningJobEventType) IsKnown() bool { + switch r { + case FineTuningJobEventTypeMessage, FineTuningJobEventTypeMetrics: + return true + } + return false +} + type FineTuningJobWandbIntegrationObject struct { // The type of the integration being enabled for the fine-tuning job Type FineTuningJobWandbIntegrationObjectType `json:"type,required"` @@ -509,17 +1073,22 @@ type FineTuningJobNewParams struct { // your file with the purpose `fine-tune`. // // The contents of the file should differ depending on if the model uses the - // [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input) or + // [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input), // [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input) + // format, or if the fine-tuning method uses the + // [preference](https://platform.openai.com/docs/api-reference/fine-tuning/preference-input) // format. // // See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning) // for more details. TrainingFile param.Field[string] `json:"training_file,required"` - // The hyperparameters used for the fine-tuning job. + // 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. Hyperparameters param.Field[FineTuningJobNewParamsHyperparameters] `json:"hyperparameters"` // A list of integrations to enable for your fine-tuning job. Integrations param.Field[[]FineTuningJobNewParamsIntegration] `json:"integrations"` + // The method used for fine-tuning. + Method param.Field[FineTuningJobNewParamsMethod] `json:"method"` // The seed controls the reproducibility of the job. Passing in the same seed and // job parameters should produce the same results, but may differ in rare cases. If // a seed is not specified, one will be generated for you. @@ -568,7 +1137,8 @@ func (r FineTuningJobNewParamsModel) IsKnown() bool { return false } -// The hyperparameters used for the fine-tuning job. +// 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. type FineTuningJobNewParamsHyperparameters struct { // Number of examples in each batch. A larger batch size means that model // parameters are updated less frequently, but with lower variance. @@ -719,6 +1289,278 @@ func (r FineTuningJobNewParamsIntegrationsWandb) MarshalJSON() (data []byte, err return apijson.MarshalRoot(r) } +// The method used for fine-tuning. +type FineTuningJobNewParamsMethod struct { + // Configuration for the DPO fine-tuning method. + Dpo param.Field[FineTuningJobNewParamsMethodDpo] `json:"dpo"` + // Configuration for the supervised fine-tuning method. + Supervised param.Field[FineTuningJobNewParamsMethodSupervised] `json:"supervised"` + // The type of method. Is either `supervised` or `dpo`. + Type param.Field[FineTuningJobNewParamsMethodType] `json:"type"` +} + +func (r FineTuningJobNewParamsMethod) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +// Configuration for the DPO fine-tuning method. +type FineTuningJobNewParamsMethodDpo struct { + // The hyperparameters used for the fine-tuning job. + Hyperparameters param.Field[FineTuningJobNewParamsMethodDpoHyperparameters] `json:"hyperparameters"` +} + +func (r FineTuningJobNewParamsMethodDpo) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +// The hyperparameters used for the fine-tuning job. +type FineTuningJobNewParamsMethodDpoHyperparameters struct { + // Number of examples in each batch. A larger batch size means that model + // parameters are updated less frequently, but with lower variance. + BatchSize param.Field[FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeUnion] `json:"batch_size"` + // The beta value for the DPO method. A higher beta value will increase the weight + // of the penalty between the policy and reference model. + Beta param.Field[FineTuningJobNewParamsMethodDpoHyperparametersBetaUnion] `json:"beta"` + // Scaling factor for the learning rate. A smaller learning rate may be useful to + // avoid overfitting. + LearningRateMultiplier param.Field[FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierUnion] `json:"learning_rate_multiplier"` + // The number of epochs to train the model for. An epoch refers to one full cycle + // through the training dataset. + NEpochs param.Field[FineTuningJobNewParamsMethodDpoHyperparametersNEpochsUnion] `json:"n_epochs"` +} + +func (r FineTuningJobNewParamsMethodDpoHyperparameters) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +// Number of examples in each batch. A larger batch size means that model +// parameters are updated less frequently, but with lower variance. +// +// Satisfied by [FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeAuto], +// [shared.UnionInt]. +type FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeUnion interface { + ImplementsFineTuningJobNewParamsMethodDpoHyperparametersBatchSizeUnion() +} + +type FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeAuto string + +const ( + FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeAutoAuto FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeAuto = "auto" +) + +func (r FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeAuto) IsKnown() bool { + switch r { + case FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeAutoAuto: + return true + } + return false +} + +func (r FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeAuto) ImplementsFineTuningJobNewParamsMethodDpoHyperparametersBatchSizeUnion() { +} + +// The beta value for the DPO method. A higher beta value will increase the weight +// of the penalty between the policy and reference model. +// +// Satisfied by [FineTuningJobNewParamsMethodDpoHyperparametersBetaAuto], +// [shared.UnionFloat]. +type FineTuningJobNewParamsMethodDpoHyperparametersBetaUnion interface { + ImplementsFineTuningJobNewParamsMethodDpoHyperparametersBetaUnion() +} + +type FineTuningJobNewParamsMethodDpoHyperparametersBetaAuto string + +const ( + FineTuningJobNewParamsMethodDpoHyperparametersBetaAutoAuto FineTuningJobNewParamsMethodDpoHyperparametersBetaAuto = "auto" +) + +func (r FineTuningJobNewParamsMethodDpoHyperparametersBetaAuto) IsKnown() bool { + switch r { + case FineTuningJobNewParamsMethodDpoHyperparametersBetaAutoAuto: + return true + } + return false +} + +func (r FineTuningJobNewParamsMethodDpoHyperparametersBetaAuto) ImplementsFineTuningJobNewParamsMethodDpoHyperparametersBetaUnion() { +} + +// Scaling factor for the learning rate. A smaller learning rate may be useful to +// avoid overfitting. +// +// Satisfied by +// [FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierAuto], +// [shared.UnionFloat]. +type FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierUnion interface { + ImplementsFineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierUnion() +} + +type FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierAuto string + +const ( + FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierAutoAuto FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierAuto = "auto" +) + +func (r FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierAuto) IsKnown() bool { + switch r { + case FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierAutoAuto: + return true + } + return false +} + +func (r FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierAuto) ImplementsFineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierUnion() { +} + +// The number of epochs to train the model for. An epoch refers to one full cycle +// through the training dataset. +// +// Satisfied by [FineTuningJobNewParamsMethodDpoHyperparametersNEpochsAuto], +// [shared.UnionInt]. +type FineTuningJobNewParamsMethodDpoHyperparametersNEpochsUnion interface { + ImplementsFineTuningJobNewParamsMethodDpoHyperparametersNEpochsUnion() +} + +type FineTuningJobNewParamsMethodDpoHyperparametersNEpochsAuto string + +const ( + FineTuningJobNewParamsMethodDpoHyperparametersNEpochsAutoAuto FineTuningJobNewParamsMethodDpoHyperparametersNEpochsAuto = "auto" +) + +func (r FineTuningJobNewParamsMethodDpoHyperparametersNEpochsAuto) IsKnown() bool { + switch r { + case FineTuningJobNewParamsMethodDpoHyperparametersNEpochsAutoAuto: + return true + } + return false +} + +func (r FineTuningJobNewParamsMethodDpoHyperparametersNEpochsAuto) ImplementsFineTuningJobNewParamsMethodDpoHyperparametersNEpochsUnion() { +} + +// Configuration for the supervised fine-tuning method. +type FineTuningJobNewParamsMethodSupervised struct { + // The hyperparameters used for the fine-tuning job. + Hyperparameters param.Field[FineTuningJobNewParamsMethodSupervisedHyperparameters] `json:"hyperparameters"` +} + +func (r FineTuningJobNewParamsMethodSupervised) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +// The hyperparameters used for the fine-tuning job. +type FineTuningJobNewParamsMethodSupervisedHyperparameters struct { + // Number of examples in each batch. A larger batch size means that model + // parameters are updated less frequently, but with lower variance. + BatchSize param.Field[FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeUnion] `json:"batch_size"` + // Scaling factor for the learning rate. A smaller learning rate may be useful to + // avoid overfitting. + LearningRateMultiplier param.Field[FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierUnion] `json:"learning_rate_multiplier"` + // The number of epochs to train the model for. An epoch refers to one full cycle + // through the training dataset. + NEpochs param.Field[FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsUnion] `json:"n_epochs"` +} + +func (r FineTuningJobNewParamsMethodSupervisedHyperparameters) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +// Number of examples in each batch. A larger batch size means that model +// parameters are updated less frequently, but with lower variance. +// +// Satisfied by +// [FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeAuto], +// [shared.UnionInt]. +type FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeUnion interface { + ImplementsFineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeUnion() +} + +type FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeAuto string + +const ( + FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeAutoAuto FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeAuto = "auto" +) + +func (r FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeAuto) IsKnown() bool { + switch r { + case FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeAutoAuto: + return true + } + return false +} + +func (r FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeAuto) ImplementsFineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeUnion() { +} + +// Scaling factor for the learning rate. A smaller learning rate may be useful to +// avoid overfitting. +// +// Satisfied by +// [FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierAuto], +// [shared.UnionFloat]. +type FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierUnion interface { + ImplementsFineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierUnion() +} + +type FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierAuto string + +const ( + FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierAutoAuto FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierAuto = "auto" +) + +func (r FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierAuto) IsKnown() bool { + switch r { + case FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierAutoAuto: + return true + } + return false +} + +func (r FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierAuto) ImplementsFineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierUnion() { +} + +// The number of epochs to train the model for. An epoch refers to one full cycle +// through the training dataset. +// +// Satisfied by [FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsAuto], +// [shared.UnionInt]. +type FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsUnion interface { + ImplementsFineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsUnion() +} + +type FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsAuto string + +const ( + FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsAutoAuto FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsAuto = "auto" +) + +func (r FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsAuto) IsKnown() bool { + switch r { + case FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsAutoAuto: + return true + } + return false +} + +func (r FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsAuto) ImplementsFineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsUnion() { +} + +// The type of method. Is either `supervised` or `dpo`. +type FineTuningJobNewParamsMethodType string + +const ( + FineTuningJobNewParamsMethodTypeSupervised FineTuningJobNewParamsMethodType = "supervised" + FineTuningJobNewParamsMethodTypeDpo FineTuningJobNewParamsMethodType = "dpo" +) + +func (r FineTuningJobNewParamsMethodType) IsKnown() bool { + switch r { + case FineTuningJobNewParamsMethodTypeSupervised, FineTuningJobNewParamsMethodTypeDpo: + return true + } + return false +} + type FineTuningJobListParams struct { // Identifier for the last job from the previous pagination request. After param.Field[string] `query:"after"` diff --git a/finetuningjob_test.go b/finetuningjob_test.go index cc73082..09aef6b 100644 --- a/finetuningjob_test.go +++ b/finetuningjob_test.go @@ -42,6 +42,24 @@ func TestFineTuningJobNewWithOptionalParams(t *testing.T) { Tags: openai.F([]string{"custom-tag"}), }), }}), + Method: openai.F(openai.FineTuningJobNewParamsMethod{ + Dpo: openai.F(openai.FineTuningJobNewParamsMethodDpo{ + Hyperparameters: openai.F(openai.FineTuningJobNewParamsMethodDpoHyperparameters{ + BatchSize: openai.F[openai.FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeUnion](openai.FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeAuto(openai.FineTuningJobNewParamsMethodDpoHyperparametersBatchSizeAutoAuto)), + Beta: openai.F[openai.FineTuningJobNewParamsMethodDpoHyperparametersBetaUnion](openai.FineTuningJobNewParamsMethodDpoHyperparametersBetaAuto(openai.FineTuningJobNewParamsMethodDpoHyperparametersBetaAutoAuto)), + LearningRateMultiplier: openai.F[openai.FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierUnion](openai.FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierAuto(openai.FineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierAutoAuto)), + NEpochs: openai.F[openai.FineTuningJobNewParamsMethodDpoHyperparametersNEpochsUnion](openai.FineTuningJobNewParamsMethodDpoHyperparametersNEpochsAuto(openai.FineTuningJobNewParamsMethodDpoHyperparametersNEpochsAutoAuto)), + }), + }), + Supervised: openai.F(openai.FineTuningJobNewParamsMethodSupervised{ + Hyperparameters: openai.F(openai.FineTuningJobNewParamsMethodSupervisedHyperparameters{ + BatchSize: openai.F[openai.FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeUnion](openai.FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeAuto(openai.FineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeAutoAuto)), + LearningRateMultiplier: openai.F[openai.FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierUnion](openai.FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierAuto(openai.FineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierAutoAuto)), + NEpochs: openai.F[openai.FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsUnion](openai.FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsAuto(openai.FineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsAutoAuto)), + }), + }), + Type: openai.F(openai.FineTuningJobNewParamsMethodTypeSupervised), + }), Seed: openai.F(int64(42)), Suffix: openai.F("x"), ValidationFile: openai.F("file-abc123"), diff --git a/shared/union.go b/shared/union.go index 9197f98..6ca6e3f 100644 --- a/shared/union.go +++ b/shared/union.go @@ -12,10 +12,29 @@ func (UnionString) ImplementsModerationNewParamsInputUnion() {} type UnionInt int64 -func (UnionInt) ImplementsFineTuningJobHyperparametersNEpochsUnion() {} -func (UnionInt) ImplementsFineTuningJobNewParamsHyperparametersBatchSizeUnion() {} -func (UnionInt) ImplementsFineTuningJobNewParamsHyperparametersNEpochsUnion() {} +func (UnionInt) ImplementsFineTuningJobHyperparametersBatchSizeUnion() {} +func (UnionInt) ImplementsFineTuningJobHyperparametersNEpochsUnion() {} +func (UnionInt) ImplementsFineTuningJobMethodDpoHyperparametersBatchSizeUnion() {} +func (UnionInt) ImplementsFineTuningJobMethodDpoHyperparametersNEpochsUnion() {} +func (UnionInt) ImplementsFineTuningJobMethodSupervisedHyperparametersBatchSizeUnion() {} +func (UnionInt) ImplementsFineTuningJobMethodSupervisedHyperparametersNEpochsUnion() {} +func (UnionInt) ImplementsFineTuningJobNewParamsHyperparametersBatchSizeUnion() {} +func (UnionInt) ImplementsFineTuningJobNewParamsHyperparametersNEpochsUnion() {} +func (UnionInt) ImplementsFineTuningJobNewParamsMethodDpoHyperparametersBatchSizeUnion() {} +func (UnionInt) ImplementsFineTuningJobNewParamsMethodDpoHyperparametersNEpochsUnion() {} +func (UnionInt) ImplementsFineTuningJobNewParamsMethodSupervisedHyperparametersBatchSizeUnion() {} +func (UnionInt) ImplementsFineTuningJobNewParamsMethodSupervisedHyperparametersNEpochsUnion() {} type UnionFloat float64 +func (UnionFloat) ImplementsFineTuningJobHyperparametersLearningRateMultiplierUnion() {} +func (UnionFloat) ImplementsFineTuningJobMethodDpoHyperparametersBetaUnion() {} +func (UnionFloat) ImplementsFineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion() {} +func (UnionFloat) ImplementsFineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion() { +} func (UnionFloat) ImplementsFineTuningJobNewParamsHyperparametersLearningRateMultiplierUnion() {} +func (UnionFloat) ImplementsFineTuningJobNewParamsMethodDpoHyperparametersBetaUnion() {} +func (UnionFloat) ImplementsFineTuningJobNewParamsMethodDpoHyperparametersLearningRateMultiplierUnion() { +} +func (UnionFloat) ImplementsFineTuningJobNewParamsMethodSupervisedHyperparametersLearningRateMultiplierUnion() { +} diff --git a/usage_test.go b/usage_test.go index 14d8501..930d2d8 100644 --- a/usage_test.go +++ b/usage_test.go @@ -29,7 +29,7 @@ func TestUsage(t *testing.T) { Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser), Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}), }}), - Model: openai.F(openai.ChatModelO1Preview), + Model: openai.F(openai.ChatModelO1), }) if err != nil { t.Error(err)