ai.go 914 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package aiser
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/http"
  5. "hongze/hz_crm_api/utils"
  6. )
  7. func ChatAutoMsg(prompt string, model int) (result string, err error) {
  8. chatUrl := `http://47.254.37.124:8399/v1/chat/auto_msg`
  9. param := make(map[string]interface{})
  10. param["Prompt"] = prompt
  11. param["Model"] = model
  12. postData, err := json.Marshal(param)
  13. if err != nil {
  14. return result, err
  15. }
  16. utils.FileLogChat.Info("postData:" + string(postData))
  17. body, err := http.HttpPost(chatUrl, string(postData), "application/json; charset=utf-8")
  18. if err != nil {
  19. return result, err
  20. }
  21. utils.FileLogChat.Info("result:" + string(body))
  22. resp := new(ChatAutoMsgResp)
  23. err = json.Unmarshal(body, &resp)
  24. if err != nil {
  25. return result, err
  26. }
  27. if resp.Ret != 200 {
  28. return resp.Msg, nil
  29. }
  30. result = resp.Data
  31. return result, nil
  32. }
  33. type ChatAutoMsgResp struct {
  34. Ret int
  35. Data string
  36. Msg string
  37. }