node.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. triggerClassName='!h-6 !rounded-md'
  31. modelList={textGenerationModelList}
  32. readonly
  33. />
  34. )}
  35. {
  36. !!topics.length && (
  37. <div className='mt-2 space-y-0.5'>
  38. {topics.map((topic, index) => (
  39. <div
  40. key={index}
  41. className='relative'
  42. >
  43. <InfoPanel
  44. title={`${t(`${i18nPrefix}.class`)} ${index + 1}`}
  45. content={topic.name}
  46. />
  47. <NodeSourceHandle
  48. {...props}
  49. handleId={topic.id}
  50. handleClassName='!top-1/2 !-translate-y-1/2 !-right-[21px]'
  51. />
  52. </div>
  53. ))}
  54. </div>
  55. )
  56. }
  57. </div>
  58. )
  59. }
  60. export default React.memo(Node)