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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. "strconv"
  12. )
  13. type TextToTextInferenceLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewTextToTextInferenceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TextToTextInferenceLogic {
  19. return &TextToTextInferenceLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *TextToTextInferenceLogic) TextToTextInference(req *types.TextToTextInferenceReq) (resp *types.TextToTextInferenceResp, err error) {
  26. resp = &types.TextToTextInferenceResp{}
  27. instance, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(req.InstanceId)
  28. if err != nil {
  29. return nil, err
  30. }
  31. if instance == nil {
  32. return nil, errors.New("instance is empty ")
  33. }
  34. adapterId := strconv.FormatInt(instance.AdapterId, 10)
  35. opt := &option.InferOption{
  36. TaskName: req.TaskName,
  37. TaskDesc: req.TaskDesc,
  38. ModelType: req.ModelType,
  39. AdapterId: adapterId,
  40. }
  41. adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
  42. infer, err := textInference.NewTextToText(opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, instance)
  43. if err != nil {
  44. return nil, err
  45. }
  46. textInfer, err := textInference.New(infer, opt, l.svcCtx.Scheduler.AiStorages, adapterName)
  47. if err != nil {
  48. return nil, err
  49. }
  50. in := inference.Inference{
  51. In: textInfer,
  52. }
  53. id, err := in.In.CreateTask()
  54. if err != nil {
  55. return nil, err
  56. }
  57. err = in.In.InferTask(id)
  58. if err != nil {
  59. return nil, err
  60. }
  61. return resp, nil
  62. }

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.