From 0d5256fb820a34a95b8944b9410a1e562087cd8f Mon Sep 17 00:00:00 2001 From: Brendan Martin Date: Mon, 25 Sep 2023 04:08:45 -0400 Subject: [PATCH] added delete fine tune model endpoint (#497) --- client_test.go | 3 +++ models.go | 20 ++++++++++++++++++++ models_test.go | 15 +++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/client_test.go b/client_test.go index 9b5046899..2c1d749ed 100644 --- a/client_test.go +++ b/client_test.go @@ -271,6 +271,9 @@ func TestClientReturnsRequestBuilderErrors(t *testing.T) { {"GetModel", func() (any, error) { return client.GetModel(ctx, "text-davinci-003") }}, + {"DeleteFineTuneModel", func() (any, error) { + return client.DeleteFineTuneModel(ctx, "") + }}, } for _, testCase := range testCases { diff --git a/models.go b/models.go index 560402e3f..c207f0a86 100644 --- a/models.go +++ b/models.go @@ -33,6 +33,13 @@ type Permission struct { IsBlocking bool `json:"is_blocking"` } +// FineTuneModelDeleteResponse represents the deletion status of a fine-tuned model. +type FineTuneModelDeleteResponse struct { + ID string `json:"id"` + Object string `json:"object"` + Deleted bool `json:"deleted"` +} + // ModelsList is a list of models, including those that belong to the user or organization. type ModelsList struct { Models []Model `json:"data"` @@ -62,3 +69,16 @@ func (c *Client) GetModel(ctx context.Context, modelID string) (model Model, err err = c.sendRequest(req, &model) return } + +// DeleteFineTuneModel Deletes a fine-tune model. You must have the Owner +// role in your organization to delete a model. +func (c *Client) DeleteFineTuneModel(ctx context.Context, modelID string) ( + response FineTuneModelDeleteResponse, err error) { + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL("/models/"+modelID)) + if err != nil { + return + } + + err = c.sendRequest(req, &response) + return +} diff --git a/models_test.go b/models_test.go index 59b4f5ef7..9ff73042a 100644 --- a/models_test.go +++ b/models_test.go @@ -14,6 +14,8 @@ import ( "testing" ) +const testFineTuneModelID = "fine-tune-model-id" + // TestListModels Tests the list models endpoint of the API using the mocked server. func TestListModels(t *testing.T) { client, server, teardown := setupOpenAITestServer() @@ -78,3 +80,16 @@ func TestGetModelReturnTimeoutError(t *testing.T) { t.Fatal("Did not return timeout error") } } + +func TestDeleteFineTuneModel(t *testing.T) { + client, server, teardown := setupOpenAITestServer() + defer teardown() + server.RegisterHandler("/v1/models/"+testFineTuneModelID, handleDeleteFineTuneModelEndpoint) + _, err := client.DeleteFineTuneModel(context.Background(), testFineTuneModelID) + checks.NoError(t, err, "DeleteFineTuneModel error") +} + +func handleDeleteFineTuneModelEndpoint(w http.ResponseWriter, _ *http.Request) { + resBytes, _ := json.Marshal(FineTuneModelDeleteResponse{}) + fmt.Fprintln(w, string(resBytes)) +}