-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPT.go
44 lines (37 loc) · 1012 Bytes
/
GPT.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
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/go-resty/resty/v2"
)
func getGPT() {
apiKey := "" //chatGPTApiKey
client := resty.New()
response, err := client.R().
SetAuthToken(apiKey).
SetHeader("Content-Type", "application/json").
SetBody(map[string]interface{}{
"model": "gpt-4o-mini",
"messages": []interface{}{
map[string]interface{}{"role": "system", "content": "Hi can you tell me what is the factorial of 10?"},
},
"max_tokens": 50,
}).
Post(apiEndpoint)
if err != nil {
log.Fatalf("Error while sending the request: %v", err)
}
body := response.Body()
var data map[string]interface{}
err = json.Unmarshal(body, &data)
if err != nil {
fmt.Println("Error while decoding JSON response:", err)
return
}
for key, value := range data {
fmt.Printf("key: %s, value: %s\n", key, value)
}
//content := data["choices"].([]interface{})[0].(map[string]interface{})["message"].(map[string]interface{})["content"].(string)
fmt.Println("Here")
}