MCPcopy Create free account
hub / github.com/FloatTech/AnimeAPI / chat

Function chat

aireply/chatgpt.go:70–109  ·  view source on GitHub ↗
(msg string, apiKey string, url string)

Source from the content-addressed store, hash-verified

68}
69
70func chat(msg string, apiKey string, url string) string {
71 requestBody := chatGPTRequestBody{
72 Model: "text-davinci-003",
73 Prompt: msg,
74 MaxTokens: 2048,
75 Temperature: 0.7,
76 TopP: 1,
77 FrequencyPenalty: 0,
78 PresencePenalty: 0,
79 }
80 requestData := bytes.NewBuffer(make([]byte, 0, 1024*1024))
81 err := json.NewEncoder(requestData).Encode(&requestBody)
82 if err != nil {
83 return err.Error()
84 }
85 req, err := http.NewRequest("POST", url+"completions", requestData)
86 if err != nil {
87 return err.Error()
88 }
89
90 req.Header.Set("Content-Type", "application/json")
91 req.Header.Set("Authorization", "Bearer "+apiKey)
92 client := &http.Client{}
93 response, err := client.Do(req)
94 if err != nil {
95 return err.Error()
96 }
97 defer response.Body.Close()
98 var gptResponseBody chatGPTResponseBody
99 err = json.NewDecoder(response.Body).Decode(&gptResponseBody)
100 if err != nil {
101 return err.Error()
102 }
103 if len(gptResponseBody.Choices) > 0 {
104 for _, v := range gptResponseBody.Choices {
105 return fmt.Sprint(v["text"])
106 }
107 }
108 return ""
109}

Callers 1

TalkMethod · 0.85

Calls 1

SetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…