package aiser

import (
	"encoding/json"
	"github.com/rdlucklib/rdluck_tools/http"
	"hongze/hz_crm_api/utils"
)

func ChatAutoMsg(prompt string, model int) (result string, err error) {
	chatUrl := `http://47.254.37.124: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
}
