-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from henomis/feat/implement-new-fine-tuning-API
feat: implement new fine tuning API
- Loading branch information
Showing
8 changed files
with
270 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package openaigo | ||
|
||
type FineTuningJob struct { | ||
ID string `json:"id"` | ||
Object string `json:"object"` | ||
CreatedAt int64 `json:"created_at"` | ||
FinishedAt int64 `json:"finished_at"` | ||
Model string `json:"model"` | ||
FineTunedModel string `json:"fine_tuned_model,omitempty"` | ||
OrganizationID string `json:"organization_id"` | ||
Status string `json:"status"` | ||
Hyperparameters Hyperparameters `json:"hyperparameters"` | ||
TrainingFile string `json:"training_file"` | ||
ValidationFile string `json:"validation_file,omitempty"` | ||
ResultFiles []string `json:"result_files"` | ||
TrainedTokens int `json:"trained_tokens"` | ||
} | ||
|
||
type Hyperparameters struct { | ||
Epochs int `json:"n_epochs"` | ||
} | ||
|
||
type FineTuningCreateRequestBody struct { | ||
TrainingFile string `json:"training_file"` | ||
ValidationFile string `json:"validation_file,omitempty"` | ||
Model string `json:"model,omitempty"` | ||
Hyperparameters *Hyperparameters `json:"hyperparameters,omitempty"` | ||
Suffix string `json:"suffix,omitempty"` | ||
} | ||
|
||
type FineTuningListEventsResponse struct { | ||
Object string `json:"object"` | ||
Data []FineTuneEvent `json:"data"` | ||
HasMore bool `json:"has_more"` | ||
} | ||
|
||
type FineTuningEvent struct { | ||
Object string `json:"object"` | ||
ID string `json:"id"` | ||
CreatedAt int `json:"created_at"` | ||
Level string `json:"level"` | ||
Message string `json:"message"` | ||
Data any `json:"data"` | ||
Type string `json:"type"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package openaigo | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
. "github.com/otiai10/mint" | ||
) | ||
|
||
func TestClient_CreateFineTuning(t *testing.T) { | ||
client := NewClient("") | ||
client.BaseURL = mockserver.URL | ||
res, err := client.CreateFineTuning(context.TODO(), FineTuningCreateRequestBody{ | ||
TrainingFile: "file-XGinujblHPwGLSztz8cPS8XY", | ||
}) | ||
Expect(t, err).ToBe(nil) | ||
Expect(t, res).TypeOf("openaigo.FineTuningJob") | ||
} | ||
|
||
func TestClient_RetrieveFineTuning(t *testing.T) { | ||
client := NewClient("") | ||
client.BaseURL = mockserver.URL | ||
res, err := client.RetrieveFineTuning(context.TODO(), "abcdefghi") | ||
Expect(t, err).ToBe(nil) | ||
Expect(t, res).TypeOf("openaigo.FineTuningJob") | ||
} | ||
|
||
func TestClient_CancelFineTuning(t *testing.T) { | ||
client := NewClient("") | ||
client.BaseURL = mockserver.URL | ||
res, err := client.CancelFineTuning(context.TODO(), "abcdefghi") | ||
Expect(t, err).ToBe(nil) | ||
Expect(t, res).TypeOf("openaigo.FineTuningJob") | ||
} | ||
|
||
func TestClient_ListFineTuningEvents(t *testing.T) { | ||
client := NewClient("") | ||
client.BaseURL = mockserver.URL | ||
res, err := client.ListFineTuningEvents(context.TODO(), "abcdefghi") | ||
Expect(t, err).ToBe(nil) | ||
Expect(t, res).TypeOf("openaigo.FineTuningListEventsResponse") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"object": "fine_tuning.job", | ||
"id": "ft-zRdUkP4QeZqeYjDcQL0wwam1", | ||
"model": "davinci-002", | ||
"created_at": 1692661014, | ||
"finished_at": 1692661190, | ||
"fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy", | ||
"organization_id": "org-123", | ||
"result_files": [ | ||
"file-abc123" | ||
], | ||
"status": "succeeded", | ||
"validation_file": null, | ||
"training_file": "file-abc123", | ||
"hyperparameters": { | ||
"n_epochs": 4 | ||
}, | ||
"trained_tokens": 5768 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"object": "fine_tuning.job", | ||
"id": "ft-zRdUkP4QeZqeYjDcQL0wwam1", | ||
"model": "davinci-002", | ||
"created_at": 1692661014, | ||
"finished_at": 1692661190, | ||
"fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy", | ||
"organization_id": "org-123", | ||
"result_files": [ | ||
"file-abc123" | ||
], | ||
"status": "succeeded", | ||
"validation_file": null, | ||
"training_file": "file-abc123", | ||
"hyperparameters": { | ||
"n_epochs": 4 | ||
}, | ||
"trained_tokens": 5768 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"object": "list", | ||
"data": [ | ||
{ | ||
"object": "fine_tuning.job.event", | ||
"id": "ft-event-ddTJfwuMVpfLXseO0Am0Gqjm", | ||
"created_at": 1692407401, | ||
"level": "info", | ||
"message": "Fine tuning job successfully completed", | ||
"data": null, | ||
"type": "message" | ||
}, | ||
{ | ||
"object": "fine_tuning.job.event", | ||
"id": "ft-event-tyiGuB72evQncpH87xe505Sv", | ||
"created_at": 1692407400, | ||
"level": "info", | ||
"message": "New fine-tuned model created: ft:gpt-3.5-turbo:openai::7p4lURel", | ||
"data": null, | ||
"type": "message" | ||
} | ||
], | ||
"has_more": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"object": "fine_tuning.job", | ||
"id": "ft-zRdUkP4QeZqeYjDcQL0wwam1", | ||
"model": "davinci-002", | ||
"created_at": 1692661014, | ||
"finished_at": 1692661190, | ||
"fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy", | ||
"organization_id": "org-123", | ||
"result_files": [ | ||
"file-abc123" | ||
], | ||
"status": "succeeded", | ||
"validation_file": null, | ||
"training_file": "file-abc123", | ||
"hyperparameters": { | ||
"n_epochs": 4 | ||
}, | ||
"trained_tokens": 5768 | ||
} | ||
|