import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' import type { TFunction } from 'i18next' import type { NodeProps } from 'reactflow' import { NodeSourceHandle } from '../_base/components/node-handle' import type { QuestionClassifierNodeType } from './types' import { useTextGenerationCurrentProviderAndModelAndModelList, } from '@/app/components/header/account-setting/model-provider-page/hooks' import ModelSelector from '@/app/components/header/account-setting/model-provider-page/model-selector' import ReadonlyInputWithSelectVar from '../_base/components/readonly-input-with-select-var' import Tooltip from '@/app/components/base/tooltip' const i18nPrefix = 'workflow.nodes.questionClassifiers' const MAX_CLASS_TEXT_LENGTH = 50 type TruncatedClassItemProps = { topic: { id: string; name: string } index: number nodeId: string t: TFunction } const TruncatedClassItem: FC = ({ topic, index, nodeId, t }) => { const truncatedText = topic.name.length > MAX_CLASS_TEXT_LENGTH ? `${topic.name.slice(0, MAX_CLASS_TEXT_LENGTH)}...` : topic.name const shouldShowTooltip = topic.name.length > MAX_CLASS_TEXT_LENGTH const content = (
) return (
{`${t(`${i18nPrefix}.class`)} ${index + 1}`}
{shouldShowTooltip ? (
} > {content} ) : content} ) } const Node: FC> = (props) => { const { t } = useTranslation() const { data, id } = props const { provider, name: modelId } = data.model // const tempTopics = data.topics const topics = data.classes const { textGenerationModelList, } = useTextGenerationCurrentProviderAndModelAndModelList() const hasSetModel = provider && modelId if (!hasSetModel && !topics.length) return null return (
{hasSetModel && ( )} { !!topics.length && (
{topics.map((topic, index) => (
))}
) }
) } export default React.memo(Node)