added delete fine tune model endpoint (#497)
This commit is contained in:
@@ -271,6 +271,9 @@ func TestClientReturnsRequestBuilderErrors(t *testing.T) {
|
|||||||
{"GetModel", func() (any, error) {
|
{"GetModel", func() (any, error) {
|
||||||
return client.GetModel(ctx, "text-davinci-003")
|
return client.GetModel(ctx, "text-davinci-003")
|
||||||
}},
|
}},
|
||||||
|
{"DeleteFineTuneModel", func() (any, error) {
|
||||||
|
return client.DeleteFineTuneModel(ctx, "")
|
||||||
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
|||||||
20
models.go
20
models.go
@@ -33,6 +33,13 @@ type Permission struct {
|
|||||||
IsBlocking bool `json:"is_blocking"`
|
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.
|
// ModelsList is a list of models, including those that belong to the user or organization.
|
||||||
type ModelsList struct {
|
type ModelsList struct {
|
||||||
Models []Model `json:"data"`
|
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)
|
err = c.sendRequest(req, &model)
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const testFineTuneModelID = "fine-tune-model-id"
|
||||||
|
|
||||||
// TestListModels Tests the list models endpoint of the API using the mocked server.
|
// TestListModels Tests the list models endpoint of the API using the mocked server.
|
||||||
func TestListModels(t *testing.T) {
|
func TestListModels(t *testing.T) {
|
||||||
client, server, teardown := setupOpenAITestServer()
|
client, server, teardown := setupOpenAITestServer()
|
||||||
@@ -78,3 +80,16 @@ func TestGetModelReturnTimeoutError(t *testing.T) {
|
|||||||
t.Fatal("Did not return timeout error")
|
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))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user