您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. import ReadonlyInputWithSelectVar from '../_base/components/readonly-input-with-select-var'
  13. const i18nPrefix = 'workflow.nodes.questionClassifiers'
  14. const Node: FC<NodeProps<QuestionClassifierNodeType>> = (props) => {
  15. const { t } = useTranslation()
  16. const { data, id } = props
  17. const { provider, name: modelId } = data.model
  18. // const tempTopics = data.topics
  19. const topics = data.classes
  20. const {
  21. textGenerationModelList,
  22. } = useTextGenerationCurrentProviderAndModelAndModelList()
  23. const hasSetModel = provider && modelId
  24. if (!hasSetModel && !topics.length)
  25. return null
  26. return (
  27. <div className='mb-1 px-3 py-1'>
  28. {hasSetModel && (
  29. <ModelSelector
  30. defaultModel={{ provider, model: modelId }}
  31. triggerClassName='!h-6 !rounded-md'
  32. modelList={textGenerationModelList}
  33. readonly
  34. />
  35. )}
  36. {
  37. !!topics.length && (
  38. <div className='mt-2 space-y-0.5'>
  39. {topics.map((topic, index) => (
  40. <div
  41. key={index}
  42. className='relative'
  43. >
  44. <InfoPanel
  45. title={`${t(`${i18nPrefix}.class`)} ${index + 1}`}
  46. content={
  47. <ReadonlyInputWithSelectVar
  48. value={topic.name}
  49. nodeId={id}
  50. />
  51. }
  52. />
  53. <NodeSourceHandle
  54. {...props}
  55. handleId={topic.id}
  56. handleClassName='!top-1/2 !-translate-y-1/2 !-right-[21px]'
  57. />
  58. </div>
  59. ))}
  60. </div>
  61. )
  62. }
  63. </div>
  64. )
  65. }
  66. export default React.memo(Node)