-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (36 loc) · 996 Bytes
/
main.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
package main
import (
"context"
"fmt"
otiai10 "github.com/otiai10/openaigo"
sashabaranov "github.com/sashabaranov/go-openai"
"github.com/emikhalev/chatgpt-golang-examples/utils"
)
func main() {
ctx := context.Background()
apiKey := utils.APIKey()
fileID := ""
{
client := otiai10.NewClient(apiKey)
fileID = firstFileID(ctx, client)
}
{ // otiai10
client := otiai10.NewClient(apiKey)
retrieveFile, err := client.RetrieveFile(ctx, fileID)
fmt.Printf("otiai10 RetrieveFile: %v \n (err: %+v)\n\n",
utils.SPrintStruct(retrieveFile), err)
}
{ // sashabaranov
client := sashabaranov.NewClient(apiKey)
retrieveFile, err := client.GetFile(ctx, fileID)
fmt.Printf("sashabaranov RetrieveFile: %v \n (err: %+v)\n\n",
utils.SPrintStruct(retrieveFile), err)
}
}
func firstFileID(ctx context.Context, client *otiai10.Client) string {
listFiles, err := client.ListFiles(ctx)
if err != nil || len(listFiles.Data) == 0 {
return ""
}
return listFiles.Data[0].ID
}