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.

texttotextinferencelogic.go 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package inference
  2. import (
  3. "context"
  4. "errors"
  5. "github.com/zeromicro/go-zero/core/logx"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference/textInference"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  11. )
  12. type TextToTextInferenceLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewTextToTextInferenceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TextToTextInferenceLogic {
  18. return &TextToTextInferenceLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *TextToTextInferenceLogic) TextToTextInference(req *types.TextToTextInferenceReq) (resp *types.TextToTextInferenceResp, err error) {
  25. resp = &types.TextToTextInferenceResp{}
  26. opt := &option.InferOption{
  27. TaskName: req.TaskName,
  28. TaskDesc: req.TaskDesc,
  29. AdapterId: req.AdapterId,
  30. AiClusterIds: req.AiClusterIds,
  31. ModelName: req.ModelName,
  32. ModelType: req.ModelType,
  33. }
  34. _, ok := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[opt.AdapterId]
  35. if !ok {
  36. return nil, errors.New("AdapterId does not exist")
  37. }
  38. adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
  39. inType, err := textInference.NewTextToText(opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap)
  40. if err != nil {
  41. return nil, err
  42. }
  43. textInfer, err := textInference.New(inType, opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, adapterName)
  44. if err != nil {
  45. return nil, err
  46. }
  47. in := inference.Inference{
  48. In: textInfer,
  49. }
  50. id, err := in.In.CreateTask()
  51. if err != nil {
  52. return nil, err
  53. }
  54. err = in.In.InferTask(id)
  55. if err != nil {
  56. return nil, err
  57. }
  58. return resp, nil
  59. }

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.