-
Notifications
You must be signed in to change notification settings - Fork 135
/
blackboxai.go
62 lines (54 loc) · 1.33 KB
/
blackboxai.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package blackboxai
import (
"encoding/json"
"fmt"
"os"
"strings"
http "github.com/bogdanfinn/fhttp"
"github.com/aandrew-me/tgpt/v2/client"
"github.com/aandrew-me/tgpt/v2/structs"
)
func NewRequest(input string, params structs.Params, prevMessages string) (*http.Response, error) {
client, err := client.NewClient()
if err != nil {
fmt.Println(err)
os.Exit(0)
}
safeInput, _ := json.Marshal(input)
var data = strings.NewReader(fmt.Sprintf(`
{
"messages": [
%v
{
"content": %v,
"role": "user"
}
],
"id": "",
"previewToken": null,
"userId": "",
"codeModelMode": true,
"agentMode": {},
"trendingAgentMode": {},
"isMicMode": false
}
`,prevMessages, string(safeInput)))
req, err := http.NewRequest("POST", "https://www.blackbox.ai/api/chat", data)
if err != nil {
fmt.Println("\nSome error has occurred.")
fmt.Println("Error:", err)
os.Exit(0)
}
// Setting all the required headers
req.Header.Add("Accept", "*/*")
req.Header.Add("Accept-Language", "en-US,en;q=0.5")
req.Header.Add("Referer", "https://www.blackbox.ai/")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Origin", "https://www.blackbox.ai")
req.Header.Add("Alt-Used", "www.blackbox.ai")
// Return response
return (client.Do(req))
}
func GetMainText(line string) (mainText string) {
return line + "\n"
}