-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels-example.go
40 lines (33 loc) · 892 Bytes
/
models-example.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
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/Kardbord/gopenai/authentication"
"github.com/Kardbord/gopenai/models"
_ "github.com/joho/godotenv/autoload"
)
const OpenAITokenEnv = "OPENAI_API_KEY"
func init() {
key := os.Getenv(OpenAITokenEnv)
authentication.SetAPIKey(key)
}
func main() {
listresp, err := models.MakeListModelsRequest(nil)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Retreived information for %d models. Calling the \"Retrieve\" endpoint with the first one.\n", len(listresp.Data))
resp, err := models.MakeRetrieveModelRequest(listresp.Data[0].ID, nil)
if err != nil {
fmt.Println(err)
return
}
jsonResp, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Printf(`Failed to marshal response to JSON for printing, err="%s"\n`, err)
return
}
fmt.Printf("Retrieved Model Info: %s\n", string(jsonResp))
}