1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package aiser
- import (
- "encoding/json"
- "errors"
- "github.com/rdlucklib/rdluck_tools/http"
- "hongze/hz_eta_api/utils"
- )
- func ChatAutoMsg(prompt string, model int) (result string, err error) {
- if utils.ChatUrl == `` {
- err = errors.New("chatGPT服务未配置")
- return
- }
- chatUrl := `http://8.210.169.38:8399/v1/chat/auto_msg`
- param := make(map[string]interface{})
- param["Prompt"] = prompt
- param["Model"] = model
- postData, err := json.Marshal(param)
- if err != nil {
- return result, err
- }
- utils.FileLogChat.Info("postData:" + string(postData))
- body, err := http.HttpPost(chatUrl, string(postData), "application/json; charset=utf-8")
- if err != nil {
- return result, err
- }
- utils.FileLogChat.Info("result:" + string(body))
- resp := new(ChatAutoMsgResp)
- err = json.Unmarshal(body, &resp)
- if err != nil {
- return result, err
- }
- if resp.Ret != 200 {
- return resp.Msg, nil
- }
- result = resp.Data
- return result, nil
- }
- type ChatAutoMsgResp struct {
- Ret int
- Data string
- Msg string
- }
|