node.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import type { NodeProps } from 'reactflow'
  5. import InfoPanel from '../_base/components/info-panel'
  6. import { NodeSourceHandle } from '../_base/components/node-handle'
  7. import type { QuestionClassifierNodeType } from './types'
  8. import {
  9. useTextGenerationCurrentProviderAndModelAndModelList,
  10. } from '@/app/components/header/account-setting/model-provider-page/hooks'
  11. import ModelSelector from '@/app/components/header/account-setting/model-provider-page/model-selector'
  12. const i18nPrefix = 'workflow.nodes.questionClassifiers'
  13. const Node: FC<NodeProps<QuestionClassifierNodeType>> = (props) => {
  14. const { t } = useTranslation()
  15. const { data } = props
  16. const { provider, name: modelId } = data.model
  17. // const tempTopics = data.topics
  18. const topics = data.classes
  19. const {
  20. textGenerationModelList,
  21. } = useTextGenerationCurrentProviderAndModelAndModelList()
  22. const hasSetModel = provider && modelId
  23. if (!hasSetModel && !topics.length)
  24. return null
  25. return (
  26. <div className='mb-1 px-3 py-1'>
  27. {hasSetModel && (
  28. <ModelSelector
  29. defaultModel={{ provider, model: modelId }}
  30. modelList={textGenerationModelList}
  31. readonly
  32. />
  33. )}
  34. {
  35. !!topics.length && (
  36. <div className='mt-2 space-y-0.5'>
  37. {topics.map((topic, index) => (
  38. <div
  39. key={index}
  40. className='relative'
  41. >
  42. <InfoPanel
  43. title={`${t(`${i18nPrefix}.class`)} ${index + 1}`}
  44. content={topic.name}
  45. />
  46. <NodeSourceHandle
  47. {...props}
  48. handleId={topic.id}
  49. handleClassName='!top-1/2 !-translate-y-1/2 !-right-[21px]'
  50. />
  51. </div>
  52. ))}
  53. </div>
  54. )
  55. }
  56. </div>
  57. )
  58. }
  59. export default React.memo(Node)