代码拉取完成,页面将自动刷新
package gtp
//
//import (
// "bytes"
// "encoding/json"
// "errors"
// "fmt"
// "gitee.com/lmuiotctf/chatGpt_wechat/tree/master/config"
// "io/ioutil"
// "log"
// "net/http"
//)
//
//const BASEURL = "https://agent-openai.ccrui.dev/v1/"
//
//// ChatGPTResponseBody 请求体
//type ChatGPTResponseBody struct {
// ID string `json:"id"`
// Object string `json:"object"`
// Created int `json:"created"`
// Model string `json:"model"`
// Choices []ChoiceItem `json:"choices"`
// Usage map[string]interface{} `json:"usage"`
//}
//
//type ChoiceItem struct {
// Text string `json:"text"`
// Index int `json:"index"`
// Logprobs int `json:"logprobs"`
// FinishReason string `json:"finish_reason"`
//}
//
//// ChatGPTRequestBody 响应体
//type ChatGPTRequestBody struct {
// Model string `json:"model"`
// Prompt string `json:"prompt"`
// MaxTokens uint `json:"max_tokens"`
// Temperature float64 `json:"temperature"`
// TopP int `json:"top_p"`
// FrequencyPenalty int `json:"frequency_penalty"`
// PresencePenalty int `json:"presence_penalty"`
//}
//
//// Completions gtp文本模型回复
//// curl https://api.openai.com/v1/completions
//// -H "Content-Type: application/json"
//// -H "Authorization: Bearer your chatGPT key"
//// -d '{"model": "text-davinci-003", "prompt": "give me good song", "temperature": 0, "max_tokens": 7}'
//func Completions(msg string) (string, error) {
// cfg := config.LoadConfig()
// requestBody := ChatGPTRequestBody{
// Model: cfg.Model,
// Prompt: msg,
// MaxTokens: cfg.MaxTokens,
// Temperature: cfg.Temperature,
// TopP: 1,
// FrequencyPenalty: 0,
// PresencePenalty: 0,
// }
// requestData, err := json.Marshal(requestBody)
//
// if err != nil {
// return "", err
// }
// log.Printf("request gtp json string : %v", string(requestData))
// req, err := http.NewRequest("POST", BASEURL+"completions", bytes.NewBuffer(requestData))
// if err != nil {
// return "", err
// }
//
// apiKey := config.LoadConfig().ApiKey
// req.Header.Set("Content-Type", "application/json")
// req.Header.Set("Authorization", "Bearer "+apiKey)
// client := &http.Client{}
// response, err := client.Do(req)
// if err != nil {
// return "", err
// }
// defer response.Body.Close()
// if response.StatusCode != 200 {
// body, _ := ioutil.ReadAll(response.Body)
// log.Println(string(body))
// return "", errors.New(fmt.Sprintf("gtp api status code not equals 200,code is %d", response.StatusCode))
// }
// body, err := ioutil.ReadAll(response.Body)
// if err != nil {
// return "", err
// }
//
// gptResponseBody := &ChatGPTResponseBody{}
// log.Println(string(body))
// err = json.Unmarshal(body, gptResponseBody)
// if err != nil {
// return "", err
// }
//
// var reply string
// if len(gptResponseBody.Choices) > 0 {
// reply = gptResponseBody.Choices[0].Text
// }
// log.Printf("gpt response text: %s \n", reply)
// return reply, nil
//}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。