ai.go 854 B

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