-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.go
81 lines (73 loc) · 2.02 KB
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package v1
import (
"context"
"encoding/json"
"fmt"
)
const (
Models = "https://api.openai.com/v1/models"
Model = "https://api.openai.com/v1/models/%s"
)
type ModelsResponse struct {
Data []struct {
Id string `json:"id"`
Object string `json:"object"`
OwnedBy string `json:"owned_by"`
Permission []interface{} `json:"permission"`
} `json:"data"`
Object string `json:"object"`
}
type ModelResponse struct {
Id string `json:"id"`
Object string `json:"object"`
OwnedBy string `json:"owned_by"`
Permission []interface{} `json:"permission"`
}
// Models Lists the currently available models, and provides basic information about each one such as the owner and availability.
func (chat *ChatGpt) Models(ctx context.Context) (response ModelsResponse, err error) {
resp, err := chat.Get(ctx, Models, nil)
if err != nil {
fmt.Println(err)
return
}
err = json.Unmarshal(resp, &response)
if err != nil {
fmt.Println(err)
return
}
return
}
// Model Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
// param model The ID of the model to use for this request
func (chat *ChatGpt) Model(ctx context.Context, model string) (response ModelResponse, err error) {
resp, err := chat.Get(ctx, fmt.Sprintf(Model, model), nil)
if err != nil {
fmt.Println(err)
return
}
err = json.Unmarshal(resp, &response)
if err != nil {
fmt.Println(err)
return
}
return
}
type DeleteModelResponse struct {
Id string `json:"id"`
Object string `json:"object"`
Deleted bool `json:"deleted"`
}
// DeleteModel Delete a fine-tuned model. You must have the Owner role in your organization.
func (chat *ChatGpt) DeleteModel(ctx context.Context, model string) (response DeleteModelResponse, err error) {
resp, err := chat.Delete(ctx, fmt.Sprintf(Model, model), nil)
if err != nil {
fmt.Println(err)
return
}
err = json.Unmarshal(resp, &response)
if err != nil {
fmt.Println(err)
return
}
return
}