|
@@ -3,11 +3,15 @@ package aiser
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"eta/eta_api/utils"
|
|
|
- "github.com/rdlucklib/rdluck_tools/http"
|
|
|
+ "io/ioutil"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
func ChatAutoMsg(prompt string) (result string, err error) {
|
|
|
- chatUrl := utils.EtaAiUrl + `/chat/auto_msg`
|
|
|
+ chatUrl := utils.EtaAiUrl + `chat/auto_msg`
|
|
|
+
|
|
|
param := make(map[string]interface{})
|
|
|
param["Prompt"] = prompt
|
|
|
postData, err := json.Marshal(param)
|
|
@@ -15,11 +19,31 @@ func ChatAutoMsg(prompt string) (result string, err error) {
|
|
|
return result, err
|
|
|
}
|
|
|
|
|
|
+ client := &http.Client{}
|
|
|
+ //提交请求
|
|
|
+ reqest, err := http.NewRequest("POST", chatUrl, strings.NewReader(string(postData)))
|
|
|
+ businessCode := utils.BusinessCode
|
|
|
+ nonce := utils.GetRandStringNoSpecialChar(16)
|
|
|
+ timestamp := time.Now().Format(utils.FormatDateTimeUnSpace)
|
|
|
+ signature := utils.GetSign(nonce, timestamp, utils.EtaAppid, utils.EtaSecret)
|
|
|
+ //增加header选项
|
|
|
+ reqest.Header.Add("business_code", businessCode)
|
|
|
+ reqest.Header.Add("nonce", nonce)
|
|
|
+ reqest.Header.Add("timestamp", timestamp)
|
|
|
+ reqest.Header.Add("appid", utils.EtaAppid)
|
|
|
+ reqest.Header.Add("signature", signature)
|
|
|
+ reqest.Header.Set("Content-Type", "application/json")
|
|
|
+
|
|
|
utils.FileLog.Info("postData:" + string(postData))
|
|
|
- body, err := http.HttpPost(chatUrl, string(postData), "application/json; charset=utf-8")
|
|
|
+
|
|
|
+ response, err := client.Do(reqest)
|
|
|
if err != nil {
|
|
|
- return result, err
|
|
|
+ return
|
|
|
}
|
|
|
+ defer response.Body.Close()
|
|
|
+
|
|
|
+ body, err := ioutil.ReadAll(response.Body)
|
|
|
+
|
|
|
utils.FileLog.Info("result:" + string(body))
|
|
|
|
|
|
resp := new(ChatAutoMsgResp)
|