Skip to content

Commit

Permalink
added delete fine tune model endpoint (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanMartin committed Sep 25, 2023
1 parent 8e4b796 commit 0d5256f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}

0 comments on commit 0d5256f

Please sign in to comment.