You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

proxyapilogic.go 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package ai
  2. import (
  3. "bytes"
  4. "context"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
  6. tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  7. "k8s.io/apimachinery/pkg/util/json"
  8. "net/http"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type ProxyApiLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewProxyApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProxyApiLogic {
  19. return &ProxyApiLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. type ChatResult struct {
  26. Results string `json:"results"`
  27. }
  28. func (l *ProxyApiLogic) ProxyApi(req *types.ChatReq, w http.ResponseWriter) (resp *types.CommonResp, err error) {
  29. jsonBytes, err := json.Marshal(&req.ReqData)
  30. // 调用第三方接口的 POST 方法
  31. respThirdParty, err := http.Post(req.ApiUrl, "application/json", bytes.NewBuffer(jsonBytes))
  32. if err != nil {
  33. return
  34. }
  35. defer respThirdParty.Body.Close()
  36. marshal, err := json.Marshal(&respThirdParty.Body)
  37. if err != nil {
  38. return nil, result.NewDefaultError(err.Error())
  39. }
  40. json.Unmarshal(marshal, &resp)
  41. chatResult := &ChatResult{}
  42. tool.Convert(resp, &chatResult.Results)
  43. return &types.CommonResp{
  44. Code: respThirdParty.StatusCode,
  45. Msg: "success",
  46. Data: chatResult,
  47. }, nil
  48. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.