From 8dac9408c1416f941787f8170fa7e38d16f81df9 Mon Sep 17 00:00:00 2001 From: Jason Chavannes Date: Sat, 28 Jan 2023 11:14:34 -0800 Subject: [PATCH] List models (#58) --- models.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 models.go diff --git a/models.go b/models.go new file mode 100644 index 0000000..ccf2eec --- /dev/null +++ b/models.go @@ -0,0 +1,50 @@ +package gogpt + +import ( + "context" + "net/http" +) + +// Model struct represents an OpenAPI model. +type Model struct { + CreatedAt int `json:"created_at"` + ID string `json:"id"` + Object string `json:"object"` + OwnedBy string `json:"owned_by"` + Permission []Permission `json:"permission"` + Root string `json:"root"` + Parent string `json:"parent"` +} + +// Permission struct represents an OpenAPI permission. +type Permission struct { + CreatedAt int `json:"created_at"` + ID string `json:"id"` + Object string `json:"object"` + AllowCreateEngine bool `json:"allow_create_engine"` + AllowSampling bool `json:"allow_sampling"` + AllowLogprobs bool `json:"allow_logprobs"` + AllowSearchIndices bool `json:"allow_search_indices"` + AllowView bool `json:"allow_view"` + AllowFineTuning bool `json:"allow_fine_tuning"` + Organization string `json:"organization"` + Group interface{} `json:"group"` + IsBlocking bool `json:"is_blocking"` +} + +// ModelsList is a list of models, including those that belong to the user or organization. +type ModelsList struct { + Models []Model `json:"data"` +} + +// ListModels Lists the currently available models, +// and provides basic information about each model such as the model id and parent. +func (c *Client) ListModels(ctx context.Context) (models ModelsList, err error) { + req, err := http.NewRequest("GET", c.fullURL("/models"), nil) + if err != nil { + return + } + req = req.WithContext(ctx) + err = c.sendRequest(req, &models) + return +}