-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.go
More file actions
35 lines (31 loc) · 710 Bytes
/
models.go
File metadata and controls
35 lines (31 loc) · 710 Bytes
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
package openai
import (
"errors"
)
type realModels struct {
Object string `json:"object"`
Data []Model `json:"data"`
}
type Model struct {
ID string `json:"id"`
Object string `json:"object"`
OwnedBy string `json:"owned_by"`
}
// api /models 的实现
func (client *Client) Models() ([]Model, error) {
req := client.newHttpClient()
result := &realModels{}
req.SetResult(result)
res, e := req.Get(client.Config.BaseUrl + "/models")
if e != nil {
return []Model{}, e
}
if res.StatusCode() != 200 {
resError, e := parseRealError(res.Body())
if e != nil {
return []Model{}, errors.New(string(res.Body()))
}
return []Model{}, errors.New(resError)
}
return result.Data, nil
}