default.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { BlockEnum } from '../../types'
  2. import type { NodeDefault } from '../../types'
  3. import { type ParameterExtractorNodeType, ReasoningModeType } 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<ParameterExtractorNodeType> = {
  7. defaultValue: {
  8. query: [],
  9. model: {
  10. provider: '',
  11. name: '',
  12. mode: 'chat',
  13. completion_params: {
  14. temperature: 0.7,
  15. },
  16. },
  17. reasoning_mode: ReasoningModeType.prompt,
  18. vision: {
  19. enabled: false,
  20. },
  21. },
  22. getAvailablePrevNodes(isChatMode: boolean) {
  23. const nodes = isChatMode
  24. ? ALL_CHAT_AVAILABLE_BLOCKS
  25. : ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
  26. return nodes
  27. },
  28. getAvailableNextNodes(isChatMode: boolean) {
  29. const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
  30. return nodes
  31. },
  32. checkValid(payload: ParameterExtractorNodeType, t: any) {
  33. let errorMessages = ''
  34. if (!errorMessages && (!payload.query || payload.query.length === 0))
  35. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.parameterExtractor.inputVar`) })
  36. if (!errorMessages && !payload.model.provider)
  37. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.parameterExtractor.model`) })
  38. if (!errorMessages && (!payload.parameters || payload.parameters.length === 0))
  39. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.parameterExtractor.extractParameters`) })
  40. if (!errorMessages) {
  41. payload.parameters.forEach((param) => {
  42. if (errorMessages)
  43. return
  44. if (!param.name) {
  45. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.parameterExtractor.addExtractParameterContent.namePlaceholder`) })
  46. return
  47. }
  48. if (!param.type) {
  49. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.parameterExtractor.addExtractParameterContent.typePlaceholder`) })
  50. return
  51. }
  52. if (!param.description)
  53. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.parameterExtractor.addExtractParameterContent.descriptionPlaceholder`) })
  54. })
  55. }
  56. if (!errorMessages && payload.vision?.enabled && !payload.vision.configs?.variable_selector?.length)
  57. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.errorMsg.fields.visionVariable`) })
  58. return {
  59. isValid: !errorMessages,
  60. errorMessage: errorMessages,
  61. }
  62. },
  63. }
  64. export default nodeDefault