Skip to content

Commit 25da859

Browse files
authored
Chore Deprecate legacy fine tunes API (#484)
* chore: add deprecation message * chore: use new fine tuning API in README example
1 parent a2ca01b commit 25da859

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,16 @@ func main() {
631631
client := openai.NewClient("your token")
632632
ctx := context.Background()
633633

634-
// create a .jsonl file with your training data
634+
// create a .jsonl file with your training data for conversational model
635635
// {"prompt": "<prompt text>", "completion": "<ideal generated text>"}
636636
// {"prompt": "<prompt text>", "completion": "<ideal generated text>"}
637637
// {"prompt": "<prompt text>", "completion": "<ideal generated text>"}
638638

639+
// chat models are trained using the following file format:
640+
// {"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "Paris, as if everyone doesn't know that already."}]}
641+
// {"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "Who wrote 'Romeo and Juliet'?"}, {"role": "assistant", "content": "Oh, just some guy named William Shakespeare. Ever heard of him?"}]}
642+
// {"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "How far is the Moon from Earth?"}, {"role": "assistant", "content": "Around 384,400 kilometers. Give or take a few, like that really matters."}]}
643+
639644
// you can use openai cli tool to validate the data
640645
// For more info - https://platform.openai.com/docs/guides/fine-tuning
641646

@@ -648,29 +653,29 @@ func main() {
648653
return
649654
}
650655

651-
// create a fine tune job
656+
// create a fine tuning job
652657
// Streams events until the job is done (this often takes minutes, but can take hours if there are many jobs in the queue or your dataset is large)
653658
// use below get method to know the status of your model
654-
tune, err := client.CreateFineTune(ctx, openai.FineTuneRequest{
659+
fineTuningJob, err := client.CreateFineTuningJob(ctx, openai.FineTuningJobRequest{
655660
TrainingFile: file.ID,
656-
Model: "ada", // babbage, curie, davinci, or a fine-tuned model created after 2022-04-21.
661+
Model: "davinci-002", // gpt-3.5-turbo-0613, babbage-002.
657662
})
658663
if err != nil {
659664
fmt.Printf("Creating new fine tune model error: %v\n", err)
660665
return
661666
}
662667

663-
getTune, err := client.GetFineTune(ctx, tune.ID)
668+
fineTuningJob, err = client.RetrieveFineTuningJob(ctx, fineTuningJob.ID)
664669
if err != nil {
665670
fmt.Printf("Getting fine tune model error: %v\n", err)
666671
return
667672
}
668-
fmt.Println(getTune.FineTunedModel)
673+
fmt.Println(fineTuningJob.FineTunedModel)
669674

670-
// once the status of getTune is `succeeded`, you can use your fine tune model in Completion Request
675+
// once the status of fineTuningJob is `succeeded`, you can use your fine tune model in Completion Request or Chat Completion Request
671676

672677
// resp, err := client.CreateCompletion(ctx, openai.CompletionRequest{
673-
// Model: getTune.FineTunedModel,
678+
// Model: fineTuningJob.FineTunedModel,
674679
// Prompt: "your prompt",
675680
// })
676681
// if err != nil {

fine_tunes.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"net/http"
77
)
88

9+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
10+
// This API will be officially deprecated on January 4th, 2024.
11+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
912
type FineTuneRequest struct {
1013
TrainingFile string `json:"training_file"`
1114
ValidationFile string `json:"validation_file,omitempty"`
@@ -21,6 +24,9 @@ type FineTuneRequest struct {
2124
Suffix string `json:"suffix,omitempty"`
2225
}
2326

27+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
28+
// This API will be officially deprecated on January 4th, 2024.
29+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
2430
type FineTune struct {
2531
ID string `json:"id"`
2632
Object string `json:"object"`
@@ -37,35 +43,54 @@ type FineTune struct {
3743
UpdatedAt int64 `json:"updated_at"`
3844
}
3945

46+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
47+
// This API will be officially deprecated on January 4th, 2024.
48+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
4049
type FineTuneEvent struct {
4150
Object string `json:"object"`
4251
CreatedAt int64 `json:"created_at"`
4352
Level string `json:"level"`
4453
Message string `json:"message"`
4554
}
4655

56+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
57+
// This API will be officially deprecated on January 4th, 2024.
58+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
4759
type FineTuneHyperParams struct {
4860
BatchSize int `json:"batch_size"`
4961
LearningRateMultiplier float64 `json:"learning_rate_multiplier"`
5062
Epochs int `json:"n_epochs"`
5163
PromptLossWeight float64 `json:"prompt_loss_weight"`
5264
}
5365

66+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
67+
// This API will be officially deprecated on January 4th, 2024.
68+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
5469
type FineTuneList struct {
5570
Object string `json:"object"`
5671
Data []FineTune `json:"data"`
5772
}
73+
74+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
75+
// This API will be officially deprecated on January 4th, 2024.
76+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
5877
type FineTuneEventList struct {
5978
Object string `json:"object"`
6079
Data []FineTuneEvent `json:"data"`
6180
}
6281

82+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
83+
// This API will be officially deprecated on January 4th, 2024.
84+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
6385
type FineTuneDeleteResponse struct {
6486
ID string `json:"id"`
6587
Object string `json:"object"`
6688
Deleted bool `json:"deleted"`
6789
}
6890

91+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
92+
// This API will be officially deprecated on January 4th, 2024.
93+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
6994
func (c *Client) CreateFineTune(ctx context.Context, request FineTuneRequest) (response FineTune, err error) {
7095
urlSuffix := "/fine-tunes"
7196
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request))
@@ -78,6 +103,9 @@ func (c *Client) CreateFineTune(ctx context.Context, request FineTuneRequest) (r
78103
}
79104

80105
// CancelFineTune cancel a fine-tune job.
106+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
107+
// This API will be officially deprecated on January 4th, 2024.
108+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
81109
func (c *Client) CancelFineTune(ctx context.Context, fineTuneID string) (response FineTune, err error) {
82110
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/fine-tunes/"+fineTuneID+"/cancel"))
83111
if err != nil {
@@ -88,6 +116,9 @@ func (c *Client) CancelFineTune(ctx context.Context, fineTuneID string) (respons
88116
return
89117
}
90118

119+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
120+
// This API will be officially deprecated on January 4th, 2024.
121+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
91122
func (c *Client) ListFineTunes(ctx context.Context) (response FineTuneList, err error) {
92123
req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/fine-tunes"))
93124
if err != nil {
@@ -98,6 +129,9 @@ func (c *Client) ListFineTunes(ctx context.Context) (response FineTuneList, err
98129
return
99130
}
100131

132+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
133+
// This API will be officially deprecated on January 4th, 2024.
134+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
101135
func (c *Client) GetFineTune(ctx context.Context, fineTuneID string) (response FineTune, err error) {
102136
urlSuffix := fmt.Sprintf("/fine-tunes/%s", fineTuneID)
103137
req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix))
@@ -109,6 +143,9 @@ func (c *Client) GetFineTune(ctx context.Context, fineTuneID string) (response F
109143
return
110144
}
111145

146+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
147+
// This API will be officially deprecated on January 4th, 2024.
148+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
112149
func (c *Client) DeleteFineTune(ctx context.Context, fineTuneID string) (response FineTuneDeleteResponse, err error) {
113150
req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL("/fine-tunes/"+fineTuneID))
114151
if err != nil {
@@ -119,6 +156,9 @@ func (c *Client) DeleteFineTune(ctx context.Context, fineTuneID string) (respons
119156
return
120157
}
121158

159+
// Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API.
160+
// This API will be officially deprecated on January 4th, 2024.
161+
// OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
122162
func (c *Client) ListFineTuneEvents(ctx context.Context, fineTuneID string) (response FineTuneEventList, err error) {
123163
req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/fine-tunes/"+fineTuneID+"/events"))
124164
if err != nil {

0 commit comments

Comments
 (0)