default.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import type { NodeDefault } from '../../types'
  2. import { BlockEnum } from '../../types'
  3. import type { QuestionClassifierNodeType } from './types'
  4. import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/constants'
  5. const i18nPrefix = 'workflow'
  6. const nodeDefault: NodeDefault<QuestionClassifierNodeType> = {
  7. defaultValue: {
  8. query_variable_selector: [],
  9. model: {
  10. provider: '',
  11. name: '',
  12. mode: 'chat',
  13. completion_params: {
  14. temperature: 0.7,
  15. },
  16. },
  17. classes: [
  18. {
  19. id: '1',
  20. name: '',
  21. },
  22. {
  23. id: '2',
  24. name: '',
  25. },
  26. ],
  27. vision: {
  28. enabled: false,
  29. },
  30. },
  31. getAvailablePrevNodes(isChatMode: boolean) {
  32. const nodes = isChatMode
  33. ? ALL_CHAT_AVAILABLE_BLOCKS
  34. : ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
  35. return nodes
  36. },
  37. getAvailableNextNodes(isChatMode: boolean) {
  38. const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
  39. return nodes
  40. },
  41. checkValid(payload: QuestionClassifierNodeType, t: any) {
  42. let errorMessages = ''
  43. if (!errorMessages && (!payload.query_variable_selector || payload.query_variable_selector.length === 0))
  44. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.questionClassifiers.inputVars`) })
  45. if (!errorMessages && !payload.model.provider)
  46. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.questionClassifiers.model`) })
  47. if (!errorMessages && (!payload.classes || payload.classes.length === 0))
  48. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.questionClassifiers.class`) })
  49. if (!errorMessages && (payload.classes.some(item => !item.name)))
  50. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.questionClassifiers.topicName`) })
  51. if (!errorMessages && payload.vision?.enabled && !payload.vision.configs?.variable_selector?.length)
  52. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.errorMsg.fields.visionVariable`) })
  53. return {
  54. isValid: !errorMessages,
  55. errorMessage: errorMessages,
  56. }
  57. },
  58. }
  59. export default nodeDefault