Feat: Translate the begin operator #3221 (#7811)

### What problem does this PR solve?

Feat: Translate the begin operator #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu 2025-05-23 14:18:27 +08:00 committed by GitHub
parent ab29b58316
commit e6cd799d8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 148 additions and 70 deletions

View File

@ -0,0 +1,28 @@
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from '@/components/ui/collapsible';
import { ListCollapse } from 'lucide-react';
import { PropsWithChildren, ReactNode } from 'react';
type CollapseProps = {
title?: ReactNode;
rightContent?: ReactNode;
} & PropsWithChildren;
export function Collapse({ title, children, rightContent }: CollapseProps) {
return (
<Collapsible defaultOpen>
<CollapsibleTrigger className="w-full">
<section className="flex justify-between items-center pb-2">
<div className="flex items-center gap-1">
<ListCollapse className="size-4" /> {title}
</div>
<div>{rightContent}</div>
</section>
</CollapsibleTrigger>
<CollapsibleContent>{children}</CollapsibleContent>
</Collapsible>
);
}

View File

@ -14,8 +14,7 @@ import {
import { Label } from '@/components/ui/label'; import { Label } from '@/components/ui/label';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { Info } from 'lucide-react'; import { FormTooltip } from './tooltip';
import { Tooltip, TooltipContent, TooltipTrigger } from './tooltip';
const Form = FormProvider; const Form = FormProvider;
@ -104,16 +103,7 @@ const FormLabel = React.forwardRef<
{...props} {...props}
> >
{props.children} {props.children}
{tooltip && ( {tooltip && <FormTooltip tooltip={tooltip}></FormTooltip>}
<Tooltip>
<TooltipTrigger>
<Info className="size-3 ml-2" />
</TooltipTrigger>
<TooltipContent>
<p>{tooltip}</p>
</TooltipContent>
</Tooltip>
)}
</Label> </Label>
); );
}); });

View File

@ -4,6 +4,7 @@ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
import * as React from 'react'; import * as React from 'react';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { Info } from 'lucide-react';
const TooltipProvider = TooltipPrimitive.Provider; const TooltipProvider = TooltipPrimitive.Provider;
@ -28,3 +29,16 @@ const TooltipContent = React.forwardRef<
TooltipContent.displayName = TooltipPrimitive.Content.displayName; TooltipContent.displayName = TooltipPrimitive.Content.displayName;
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger }; export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
export const FormTooltip = ({ tooltip }: { tooltip: React.ReactNode }) => {
return (
<Tooltip>
<TooltipTrigger>
<Info className="size-3 ml-2" />
</TooltipTrigger>
<TooltipContent>
<p>{tooltip}</p>
</TooltipContent>
</Tooltip>
);
};

View File

@ -455,7 +455,8 @@ This auto-tagging feature enhances retrieval by adding another layer of domain-s
modelTip: 'Large language chat model', modelTip: 'Large language chat model',
modelMessage: 'Please select!', modelMessage: 'Please select!',
modelEnabledTools: 'Enabled tools', modelEnabledTools: 'Enabled tools',
modelEnabledToolsTip: 'Please select one or more tools for the chat model to use. It takes no effect for models not supporting tool call.', modelEnabledToolsTip:
'Please select one or more tools for the chat model to use. It takes no effect for models not supporting tool call.',
freedom: 'Freedom', freedom: 'Freedom',
improvise: 'Improvise', improvise: 'Improvise',
precise: 'Precise', precise: 'Precise',
@ -1268,14 +1269,22 @@ This delimiter is used to split the input text into several text pieces echo of
codeDescription: 'It allows developers to write custom Python logic.', codeDescription: 'It allows developers to write custom Python logic.',
inputVariables: 'Input variables', inputVariables: 'Input variables',
runningHintText: 'is running...🕞', runningHintText: 'is running...🕞',
openingSwitch: 'Opening switch',
openingCopy: 'Opening copy',
openingSwitchTip:
'Your users will see this welcome message at the beginning.',
modeTip: 'The mode defines how the workflow is initiated.',
beginInputTip:
'By defining input parameters, this content can be accessed by other components in subsequent processes.',
}, },
llmTools: { llmTools: {
bad_calculator: { bad_calculator: {
name: "Calculator", name: 'Calculator',
description: "A tool to calculate the sum of two numbers (will give wrong answer)", description:
'A tool to calculate the sum of two numbers (will give wrong answer)',
params: { params: {
a: "The first number", a: 'The first number',
b: "The second number", b: 'The second number',
}, },
}, },
}, },

View File

@ -1162,6 +1162,9 @@ export default {
codeDescription: '它允許開發人員編寫自訂 Python 邏輯。', codeDescription: '它允許開發人員編寫自訂 Python 邏輯。',
inputVariables: '輸入變數', inputVariables: '輸入變數',
runningHintText: '正在運行...🕞', runningHintText: '正在運行...🕞',
openingSwitchTip: '您的用戶將在開始時看到此歡迎訊息。',
modeTip: '模式定義工作流程如何啟動。 ',
beginInputTip: `透過定義輸入參數,這些內容可以在後續流程中被其他元件存取。`,
}, },
footer: { footer: {
profile: '“保留所有權利 @ react”', profile: '“保留所有權利 @ react”',

View File

@ -462,7 +462,8 @@ General实体和关系提取提示来自 GitHub - microsoft/graphrag基于
modelTip: '大语言聊天模型', modelTip: '大语言聊天模型',
modelMessage: '请选择', modelMessage: '请选择',
modelEnabledTools: '可用的工具', modelEnabledTools: '可用的工具',
modelEnabledToolsTip: '请选择一个或多个可供该模型所使用的工具。仅对支持工具调用的模型生效。', modelEnabledToolsTip:
'请选择一个或多个可供该模型所使用的工具。仅对支持工具调用的模型生效。',
freedom: '自由度', freedom: '自由度',
improvise: '即兴创作', improvise: '即兴创作',
precise: '精确', precise: '精确',
@ -1224,6 +1225,11 @@ General实体和关系提取提示来自 GitHub - microsoft/graphrag基于
inputVariables: '输入变量', inputVariables: '输入变量',
addVariable: '新增变量', addVariable: '新增变量',
runningHintText: '正在运行中...🕞', runningHintText: '正在运行中...🕞',
openingSwitch: '开场白开关',
openingCopy: '开场白文案',
openingSwitchTip: '您的用户将在开始时看到此欢迎消息。',
modeTip: '模式定义了工作流的启动方式。',
beginInputTip: '通过定义输入参数,此内容可以被后续流程中的其他组件访问。',
}, },
footer: { footer: {
profile: 'All rights reserved @ React', profile: 'All rights reserved @ React',
@ -1235,11 +1241,11 @@ General实体和关系提取提示来自 GitHub - microsoft/graphrag基于
}, },
llmTools: { llmTools: {
bad_calculator: { bad_calculator: {
name: "计算器", name: '计算器',
description: "用于计算两个数的和的工具(会给出错误答案)", description: '用于计算两个数的和的工具(会给出错误答案)',
params: { params: {
a: "第一个数", a: '第一个数',
b: "第二个数", b: '第二个数',
}, },
}, },
}, },

View File

@ -29,7 +29,10 @@ import { ReactComponent as WenCaiIcon } from '@/assets/svg/wencai.svg';
import { ReactComponent as YahooFinanceIcon } from '@/assets/svg/yahoo-finance.svg'; import { ReactComponent as YahooFinanceIcon } from '@/assets/svg/yahoo-finance.svg';
import { CodeTemplateStrMap, ProgrammingLanguage } from '@/constants/agent'; import { CodeTemplateStrMap, ProgrammingLanguage } from '@/constants/agent';
// 邮件功能 export enum AgentDialogueMode {
Conversational = 'Conversational',
Task = 'Task',
}
import { import {
ChatVariableEnabledField, ChatVariableEnabledField,
@ -424,6 +427,7 @@ export const initialRetrievalValues = {
}; };
export const initialBeginValues = { export const initialBeginValues = {
mode: AgentDialogueMode.Conversational,
prologue: `Hi! I'm your assistant, what can I do for you?`, prologue: `Hi! I'm your assistant, what can I do for you?`,
}; };
@ -3006,8 +3010,3 @@ export const NoDebugOperatorsList = [
Operator.Switch, Operator.Switch,
Operator.Iteration, Operator.Iteration,
]; ];
export enum AgentDialogueMode {
Conversational = 'Conversational',
Task = 'Task',
}

View File

@ -49,24 +49,27 @@ export function useFormConfigMap() {
mode: AgentDialogueMode.Conversational, mode: AgentDialogueMode.Conversational,
}, },
schema: z.object({ schema: z.object({
enablePrologue: z.boolean(), enablePrologue: z.boolean().optional(),
prologue: z prologue: z
.string() .string()
.min(1, { .min(1, {
message: t('common.namePlaceholder'), message: t('common.namePlaceholder'),
}) })
.trim(), .trim()
.optional(),
mode: z.string(), mode: z.string(),
query: z.array( query: z
z.object({ .array(
key: z.string(), z.object({
type: z.string(), key: z.string(),
value: z.string(), type: z.string(),
optional: z.boolean(), value: z.string(),
name: z.string(), optional: z.boolean(),
options: z.array(z.union([z.number(), z.string(), z.boolean()])), name: z.string(),
}), options: z.array(z.union([z.number(), z.string(), z.boolean()])),
), }),
)
.optional(),
}), }),
}, },
[Operator.Retrieval]: { [Operator.Retrieval]: {

View File

@ -1,4 +1,5 @@
import { BlockButton } from '@/components/ui/button'; import { Collapse } from '@/components/collapse';
import { Button } from '@/components/ui/button';
import { import {
Form, Form,
FormControl, FormControl,
@ -10,7 +11,9 @@ import {
import { RAGFlowSelect } from '@/components/ui/select'; import { RAGFlowSelect } from '@/components/ui/select';
import { Switch } from '@/components/ui/switch'; import { Switch } from '@/components/ui/switch';
import { Textarea } from '@/components/ui/textarea'; import { Textarea } from '@/components/ui/textarea';
import { FormTooltip } from '@/components/ui/tooltip';
import { buildSelectOptions } from '@/utils/common-util'; import { buildSelectOptions } from '@/utils/common-util';
import { Plus } from 'lucide-react';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { useWatch } from 'react-hook-form'; import { useWatch } from 'react-hook-form';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -21,13 +24,16 @@ import { QueryTable } from './query-table';
import { useEditQueryRecord } from './use-edit-query'; import { useEditQueryRecord } from './use-edit-query';
const ModeOptions = buildSelectOptions([ const ModeOptions = buildSelectOptions([
(AgentDialogueMode.Conversational, AgentDialogueMode.Task), AgentDialogueMode.Conversational,
AgentDialogueMode.Task,
]); ]);
const BeginForm = ({ form, node }: INextOperatorForm) => { const BeginForm = ({ form, node }: INextOperatorForm) => {
const { t } = useTranslation(); const { t } = useTranslation();
const query = useWatch({ control: form.control, name: 'query' }); const query = useWatch({ control: form.control, name: 'query' });
const mode = useWatch({ control: form.control, name: 'mode' });
const enablePrologue = useWatch({ const enablePrologue = useWatch({
control: form.control, control: form.control,
name: 'enablePrologue', name: 'enablePrologue',
@ -61,7 +67,7 @@ const BeginForm = ({ form, node }: INextOperatorForm) => {
name={'mode'} name={'mode'}
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel tooltip={t('chat.setAnOpenerTip')}>Mode</FormLabel> <FormLabel tooltip={t('flow.modeTip')}>Mode</FormLabel>
<FormControl> <FormControl>
<RAGFlowSelect <RAGFlowSelect
placeholder={t('common.pleaseSelect')} placeholder={t('common.pleaseSelect')}
@ -73,24 +79,26 @@ const BeginForm = ({ form, node }: INextOperatorForm) => {
</FormItem> </FormItem>
)} )}
/> />
<FormField {mode === AgentDialogueMode.Conversational && (
control={form.control} <FormField
name={'enablePrologue'} control={form.control}
render={({ field }) => ( name={'enablePrologue'}
<FormItem> render={({ field }) => (
<FormLabel tooltip={t('chat.setAnOpenerTip')}> <FormItem>
Welcome Message <FormLabel tooltip={t('flow.openingSwitchTip')}>
</FormLabel> {t('flow.openingSwitch')}
<FormControl> </FormLabel>
<Switch <FormControl>
checked={field.value} <Switch
onCheckedChange={field.onChange} checked={field.value}
/> onCheckedChange={field.onChange}
</FormControl> />
<FormMessage /> </FormControl>
</FormItem> <FormMessage />
)} </FormItem>
/> )}
/>
)}
{enablePrologue && ( {enablePrologue && (
<FormField <FormField
control={form.control} control={form.control}
@ -98,7 +106,7 @@ const BeginForm = ({ form, node }: INextOperatorForm) => {
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel tooltip={t('chat.setAnOpenerTip')}> <FormLabel tooltip={t('chat.setAnOpenerTip')}>
{t('chat.setAnOpener')} {t('flow.openingCopy')}
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Textarea <Textarea
@ -118,14 +126,32 @@ const BeginForm = ({ form, node }: INextOperatorForm) => {
name={'query'} name={'query'}
render={() => <div></div>} render={() => <div></div>}
/> />
<QueryTable <Collapse
data={query} title={
showModal={showModal} <div>
deleteRecord={handleDeleteRecord} {t('flow.input')}
></QueryTable> <FormTooltip tooltip={t('flow.beginInputTip')}></FormTooltip>
<BlockButton onClick={() => showModal()}> </div>
{t('flow.addItem')} }
</BlockButton> rightContent={
<Button
variant={'ghost'}
onClick={(e) => {
e.preventDefault();
showModal();
}}
>
<Plus />
</Button>
}
>
<QueryTable
data={query}
showModal={showModal}
deleteRecord={handleDeleteRecord}
></QueryTable>
</Collapse>
{visible && ( {visible && (
<ParameterDialog <ParameterDialog
visible={visible} visible={visible}