From 6372cb7b41f03f4dce1704bf3575e550f265d544 Mon Sep 17 00:00:00 2001 From: Obada Khalili <54270856+obadakhalili@users.noreply.github.com> Date: Tue, 1 Apr 2025 05:19:36 +0200 Subject: [PATCH] Support variables in question classifier classes (#17227) --- .../nodes/_base/components/prompt/editor.tsx | 3 ++ .../components/class-item.tsx | 54 +++++++++---------- .../components/class-list.tsx | 13 +++-- .../nodes/question-classifier/node.tsx | 10 +++- .../nodes/question-classifier/panel.tsx | 3 +- 5 files changed, 46 insertions(+), 37 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx b/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx index aba0683923..cc8799bbed 100644 --- a/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx +++ b/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx @@ -73,6 +73,7 @@ type Props = { titleTooltip?: ReactNode inputClassName?: string editorContainerClassName?: string + placeholder?: string placeholderClassName?: string titleClassName?: string required?: boolean @@ -108,6 +109,7 @@ const Editor: FC = ({ gradientBorder = true, titleTooltip, inputClassName, + placeholder, placeholderClassName, titleClassName, editorContainerClassName, @@ -223,6 +225,7 @@ const Editor: FC = ({
void onRemove: () => void index: number readonly?: boolean + filterVar: (payload: Var, valueSelector: ValueSelector) => boolean } const ClassItem: FC = ({ + nodeId, payload, onChange, onRemove, index, readonly, + filterVar, }) => { const { t } = useTranslation() @@ -31,35 +34,26 @@ const ClassItem: FC = ({ onChange({ ...payload, name: value }) }, [onChange, payload]) + const { availableVars, availableNodesWithParent } = useAvailableVarList(nodeId, { + onlyLeafNodeVar: false, + hideChatVar: false, + hideEnv: false, + filterVar, + }) + return ( - -
-
- {`${t(`${i18nPrefix}.class`)} ${index}`} -
-
-
} + -
{payload.name.length}
-
- {!readonly && ( - - )} - - )} - readonly={readonly} - minHeight={64} + showRemove + onRemove={onRemove} + nodesOutputVars={availableVars} + availableNodes={availableNodesWithParent} + readOnly={readonly} // ? + justVar // ? + isSupportFileVar // ? /> ) } diff --git a/web/app/components/workflow/nodes/question-classifier/components/class-list.tsx b/web/app/components/workflow/nodes/question-classifier/components/class-list.tsx index e23c42bf97..4dc0ff759e 100644 --- a/web/app/components/workflow/nodes/question-classifier/components/class-list.tsx +++ b/web/app/components/workflow/nodes/question-classifier/components/class-list.tsx @@ -7,21 +7,24 @@ import { useEdgesInteractions } from '../../../hooks' import AddButton from '../../_base/components/add-button' import Item from './class-item' import type { Topic } from '@/app/components/workflow/nodes/question-classifier/types' +import type { ValueSelector, Var } from '@/app/components/workflow/types' const i18nPrefix = 'workflow.nodes.questionClassifiers' type Props = { - id: string + nodeId: string list: Topic[] onChange: (list: Topic[]) => void readonly?: boolean + filterVar: (payload: Var, valueSelector: ValueSelector) => boolean } const ClassList: FC = ({ - id, + nodeId, list, onChange, readonly, + filterVar, }) => { const { t } = useTranslation() const { handleEdgeDeleteByDeleteBranch } = useEdgesInteractions() @@ -44,13 +47,13 @@ const ClassList: FC = ({ const handleRemoveClass = useCallback((index: number) => { return () => { - handleEdgeDeleteByDeleteBranch(id, list[index].id) + handleEdgeDeleteByDeleteBranch(nodeId, list[index].id) const newList = produce(list, (draft) => { draft.splice(index, 1) }) onChange(newList) } - }, [list, onChange, handleEdgeDeleteByDeleteBranch, id]) + }, [list, onChange, handleEdgeDeleteByDeleteBranch, nodeId]) // Todo Remove; edit topic name return ( @@ -59,12 +62,14 @@ const ClassList: FC = ({ list.map((item, index) => { return ( ) }) diff --git a/web/app/components/workflow/nodes/question-classifier/node.tsx b/web/app/components/workflow/nodes/question-classifier/node.tsx index 8316c3b259..87ec68b021 100644 --- a/web/app/components/workflow/nodes/question-classifier/node.tsx +++ b/web/app/components/workflow/nodes/question-classifier/node.tsx @@ -9,13 +9,14 @@ 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' const i18nPrefix = 'workflow.nodes.questionClassifiers' const Node: FC> = (props) => { const { t } = useTranslation() - const { data } = props + const { data, id } = props const { provider, name: modelId } = data.model // const tempTopics = data.topics const topics = data.classes @@ -47,7 +48,12 @@ const Node: FC> = (props) => { > + } /> > = ({ title={t(`${i18nPrefix}.class`)} >