import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' import MemoryConfig from '../_base/components/memory-config' import VarReferencePicker from '../_base/components/variable/var-reference-picker' import ConfigVision from '../_base/components/config-vision' import useConfig from './use-config' import type { LLMNodeType } from './types' import ConfigPrompt from './components/config-prompt' import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list' import AddButton2 from '@/app/components/base/button/add-button' import Field from '@/app/components/workflow/nodes/_base/components/field' import Split from '@/app/components/workflow/nodes/_base/components/split' import ModelParameterModal from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal' import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars' import { InputVarType, type NodePanelProps } from '@/app/components/workflow/types' import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form' import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form' import ResultPanel from '@/app/components/workflow/run/result-panel' import Tooltip from '@/app/components/base/tooltip' import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor' const i18nPrefix = 'workflow.nodes.llm' const Panel: FC> = ({ id, data, }) => { const { t } = useTranslation() const { readOnly, inputs, isChatModel, isChatMode, isCompletionModel, shouldShowContextTip, isVisionModel, handleModelChanged, hasSetBlockStatus, handleCompletionParamsChange, handleContextVarChange, filterInputVar, filterVar, availableVars, availableNodesWithParent, isShowVars, handlePromptChange, handleAddEmptyVariable, handleAddVariable, handleVarListChange, handleVarNameChange, handleSyeQueryChange, handleMemoryChange, handleVisionResolutionEnabledChange, handleVisionResolutionChange, isShowSingleRun, hideSingleRun, inputVarValues, setInputVarValues, visionFiles, setVisionFiles, contexts, setContexts, runningStatus, handleRun, handleStop, varInputs, runResult, } = useConfig(id, data) const model = inputs.model const singleRunForms = (() => { const forms: FormProps[] = [] if (varInputs.length > 0) { forms.push( { label: t(`${i18nPrefix}.singleRun.variable`)!, inputs: varInputs, values: inputVarValues, onChange: setInputVarValues, }, ) } if (inputs.context?.variable_selector && inputs.context?.variable_selector.length > 0) { forms.push( { label: t(`${i18nPrefix}.context`)!, inputs: [{ label: '', variable: '#context#', type: InputVarType.contexts, required: false, }], values: { '#context#': contexts }, onChange: keyValue => setContexts((keyValue as any)['#context#']), }, ) } if (isVisionModel) { const variableName = data.vision.configs?.variable_selector?.[1] || t(`${i18nPrefix}.files`)! forms.push( { label: t(`${i18nPrefix}.vision`)!, inputs: [{ label: variableName!, variable: '#files#', type: InputVarType.files, required: false, }], values: { '#files#': visionFiles }, onChange: keyValue => setVisionFiles((keyValue as any)['#files#']), }, ) } return forms })() return (
{/* knowledge */} <> {shouldShowContextTip && (
{t(`${i18nPrefix}.notSetContextInPromptTip`)}
)}
{/* Prompt */} {model.name && ( )} {isShowVars && ( : undefined } > )} {/* Memory put place examples. */} {isChatMode && isChatModel && !!inputs.memory && (
{t('workflow.nodes.common.memories.title')}
{t('workflow.nodes.common.memories.builtIn')}
{/* Readonly User Query */}
user
{t('workflow.nodes.llm.roleDescription.user')}
} triggerClassName='w-4 h-4' />
} value={inputs.memory.query_prompt_template || '{{#sys.query#}}'} onChange={handleSyeQueryChange} readOnly={readOnly} isShowContext={false} isChatApp isChatModel hasSetBlockStatus={hasSetBlockStatus} nodesOutputVars={availableVars} availableNodes={availableNodesWithParent} /> {inputs.memory.query_prompt_template && !inputs.memory.query_prompt_template.includes('{{#sys.query#}}') && (
{t(`${i18nPrefix}.sysQueryInUser`)}
)}
)} {/* Memory */} {isChatMode && ( <> )} {/* Vision: GPT4-vision and so on */}
<>
{isShowSingleRun && ( } /> )} ) } export default React.memo(Panel)