ai.go 1006 B

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