Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added delete fine tune model endpoint #497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
Loading