Skip to content

Commit 0d5256f

Browse files
added delete fine tune model endpoint (#497)
1 parent 8e4b796 commit 0d5256f

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

client_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ func TestClientReturnsRequestBuilderErrors(t *testing.T) {
271271
{"GetModel", func() (any, error) {
272272
return client.GetModel(ctx, "text-davinci-003")
273273
}},
274+
{"DeleteFineTuneModel", func() (any, error) {
275+
return client.DeleteFineTuneModel(ctx, "")
276+
}},
274277
}
275278

276279
for _, testCase := range testCases {

models.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ type Permission struct {
3333
IsBlocking bool `json:"is_blocking"`
3434
}
3535

36+
// FineTuneModelDeleteResponse represents the deletion status of a fine-tuned model.
37+
type FineTuneModelDeleteResponse struct {
38+
ID string `json:"id"`
39+
Object string `json:"object"`
40+
Deleted bool `json:"deleted"`
41+
}
42+
3643
// ModelsList is a list of models, including those that belong to the user or organization.
3744
type ModelsList struct {
3845
Models []Model `json:"data"`
@@ -62,3 +69,16 @@ func (c *Client) GetModel(ctx context.Context, modelID string) (model Model, err
6269
err = c.sendRequest(req, &model)
6370
return
6471
}
72+
73+
// DeleteFineTuneModel Deletes a fine-tune model. You must have the Owner
74+
// role in your organization to delete a model.
75+
func (c *Client) DeleteFineTuneModel(ctx context.Context, modelID string) (
76+
response FineTuneModelDeleteResponse, err error) {
77+
req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL("/models/"+modelID))
78+
if err != nil {
79+
return
80+
}
81+
82+
err = c.sendRequest(req, &response)
83+
return
84+
}

models_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"testing"
1515
)
1616

17+
const testFineTuneModelID = "fine-tune-model-id"
18+
1719
// TestListModels Tests the list models endpoint of the API using the mocked server.
1820
func TestListModels(t *testing.T) {
1921
client, server, teardown := setupOpenAITestServer()
@@ -78,3 +80,16 @@ func TestGetModelReturnTimeoutError(t *testing.T) {
7880
t.Fatal("Did not return timeout error")
7981
}
8082
}
83+
84+
func TestDeleteFineTuneModel(t *testing.T) {
85+
client, server, teardown := setupOpenAITestServer()
86+
defer teardown()
87+
server.RegisterHandler("/v1/models/"+testFineTuneModelID, handleDeleteFineTuneModelEndpoint)
88+
_, err := client.DeleteFineTuneModel(context.Background(), testFineTuneModelID)
89+
checks.NoError(t, err, "DeleteFineTuneModel error")
90+
}
91+
92+
func handleDeleteFineTuneModelEndpoint(w http.ResponseWriter, _ *http.Request) {
93+
resBytes, _ := json.Marshal(FineTuneModelDeleteResponse{})
94+
fmt.Fprintln(w, string(resBytes))
95+
}

0 commit comments

Comments
 (0)