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.

textInference.go 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package textInference
  2. import (
  3. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/database"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  7. )
  8. type ITextInference interface {
  9. SaveAiTask(id int64, adapterName string) error
  10. UpdateStatus(aiTaskList []*models.TaskAi, adapterName string) error
  11. GetAiType() string
  12. }
  13. type FilteredCluster struct {
  14. urls []*inference.InferUrl
  15. clusterId string
  16. clusterName string
  17. clusterType string
  18. }
  19. type TextInference struct {
  20. inference ITextInference
  21. opt *option.InferOption
  22. storage *database.AiStorage
  23. errMap map[string]string
  24. adapterName string
  25. }
  26. func New(
  27. inference ITextInference,
  28. opt *option.InferOption,
  29. storage *database.AiStorage,
  30. adapterName string) (*TextInference, error) {
  31. return &TextInference{
  32. inference: inference,
  33. opt: opt,
  34. storage: storage,
  35. adapterName: adapterName,
  36. errMap: make(map[string]string),
  37. }, nil
  38. }
  39. func (ti *TextInference) CreateTask() (int64, error) {
  40. id, err := ti.saveTask()
  41. if err != nil {
  42. return 0, err
  43. }
  44. err = ti.saveAiTask(id)
  45. if err != nil {
  46. return 0, err
  47. }
  48. return id, nil
  49. }
  50. func (ti *TextInference) InferTask(id int64) error {
  51. aiTaskList, err := ti.storage.GetAiTaskListById(id)
  52. if err != nil || len(aiTaskList) == 0 {
  53. return err
  54. }
  55. err = ti.updateStatus(aiTaskList)
  56. if err != nil {
  57. return err
  58. }
  59. return nil
  60. }
  61. func (ti *TextInference) saveTask() (int64, error) {
  62. var synergystatus int64
  63. var strategyCode int64
  64. id, err := ti.storage.SaveTask(ti.opt.TaskName, strategyCode, synergystatus, ti.inference.GetAiType(), "", nil)
  65. if err != nil {
  66. return 0, err
  67. }
  68. return id, nil
  69. }
  70. func (ti *TextInference) saveAiTask(id int64) error {
  71. err := ti.inference.SaveAiTask(id, ti.adapterName)
  72. if err != nil {
  73. return err
  74. }
  75. return nil
  76. }
  77. func (ti *TextInference) updateStatus(aiTaskList []*models.TaskAi) error {
  78. err := ti.inference.UpdateStatus(aiTaskList, ti.adapterName)
  79. if err != nil {
  80. return err
  81. }
  82. return nil
  83. }

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.