chatApi.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package model
  2. import (
  3. "aiChat/internal/consts"
  4. "context"
  5. "github.com/gogf/gf/v2/frame/g"
  6. "github.com/gogf/gf/v2/net/gclient"
  7. "github.com/gogf/gf/v2/util/gconv"
  8. )
  9. type GPTReq struct {
  10. *BaseQuestion
  11. Identity string `json:"identity"`
  12. }
  13. type GPTRes struct {
  14. Status int `json:"status"`
  15. Response string `json:"response"`
  16. History [][]string `json:"history"`
  17. Time string `json:"time"`
  18. }
  19. var (
  20. ChatGpt = &cChatGpt{}
  21. )
  22. type cChatGpt struct {
  23. }
  24. var (
  25. tmp = []string{
  26. "smart_潜在客户_smart",
  27. }
  28. )
  29. func (c *cChatGpt) Do(ctx context.Context, qReq *QuestionReq) (res *GPTRes, err error) {
  30. gReq := GPTReq{
  31. BaseQuestion: qReq.BaseQuestion,
  32. Identity: g.Config().MustGet(ctx, "chat.api.identity", "剑鱼chat").String(),
  33. }
  34. //g.Dump(gReq)
  35. var gRes *gclient.Response
  36. gRes, err = g.Client().Header(consts.RequestJsonHeader).Post(ctx, g.Config().MustGet(ctx, "chat.api.addr", "").String(), gReq)
  37. if err != nil {
  38. return nil, err
  39. }
  40. res = &GPTRes{}
  41. err = gconv.Struct(gRes.ReadAll(), res)
  42. if err != nil {
  43. return nil, err
  44. }
  45. return
  46. }