Skip to content

Commit 8dac940

Browse files
authored
List models (#58)
1 parent b6e0908 commit 8dac940

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

models.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package gogpt
2+
3+
import (
4+
"context"
5+
"net/http"
6+
)
7+
8+
// Model struct represents an OpenAPI model.
9+
type Model struct {
10+
CreatedAt int `json:"created_at"`
11+
ID string `json:"id"`
12+
Object string `json:"object"`
13+
OwnedBy string `json:"owned_by"`
14+
Permission []Permission `json:"permission"`
15+
Root string `json:"root"`
16+
Parent string `json:"parent"`
17+
}
18+
19+
// Permission struct represents an OpenAPI permission.
20+
type Permission struct {
21+
CreatedAt int `json:"created_at"`
22+
ID string `json:"id"`
23+
Object string `json:"object"`
24+
AllowCreateEngine bool `json:"allow_create_engine"`
25+
AllowSampling bool `json:"allow_sampling"`
26+
AllowLogprobs bool `json:"allow_logprobs"`
27+
AllowSearchIndices bool `json:"allow_search_indices"`
28+
AllowView bool `json:"allow_view"`
29+
AllowFineTuning bool `json:"allow_fine_tuning"`
30+
Organization string `json:"organization"`
31+
Group interface{} `json:"group"`
32+
IsBlocking bool `json:"is_blocking"`
33+
}
34+
35+
// ModelsList is a list of models, including those that belong to the user or organization.
36+
type ModelsList struct {
37+
Models []Model `json:"data"`
38+
}
39+
40+
// ListModels Lists the currently available models,
41+
// and provides basic information about each model such as the model id and parent.
42+
func (c *Client) ListModels(ctx context.Context) (models ModelsList, err error) {
43+
req, err := http.NewRequest("GET", c.fullURL("/models"), nil)
44+
if err != nil {
45+
return
46+
}
47+
req = req.WithContext(ctx)
48+
err = c.sendRequest(req, &models)
49+
return
50+
}

0 commit comments

Comments
 (0)