Commit 6f6f0322 authored by Joel's avatar Joel

feat: choose context var

parent 0acb2db9
...@@ -6,7 +6,7 @@ import Workflow from '@/app/components/workflow' ...@@ -6,7 +6,7 @@ import Workflow from '@/app/components/workflow'
import { BlockEnum } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types'
const nodes = [ const nodes = [
BlockEnum.KnowledgeRetrieval/* 4 */, BlockEnum.Start/* 1 */, BlockEnum.DirectAnswer/* 2 */, BlockEnum.LLM/* 3 */, BlockEnum.QuestionClassifier/* 5 */, BlockEnum.LLM/* 3 */, BlockEnum.Start/* 1 */, BlockEnum.DirectAnswer/* 2 */, BlockEnum.KnowledgeRetrieval/* 4 */, BlockEnum.QuestionClassifier/* 5 */,
BlockEnum.IfElse/* 6 */, BlockEnum.Code/* 7 */, BlockEnum.TemplateTransform/* 8 */, BlockEnum.HttpRequest/* 9 */, BlockEnum.Tool/* 10 */, BlockEnum.IfElse/* 6 */, BlockEnum.Code/* 7 */, BlockEnum.TemplateTransform/* 8 */, BlockEnum.HttpRequest/* 9 */, BlockEnum.Tool/* 10 */,
BlockEnum.VariableAssigner/* 11 */, BlockEnum.End/* 12 */, BlockEnum.VariableAssigner/* 11 */, BlockEnum.End/* 12 */,
].map((item, i) => ({ ].map((item, i) => ({
......
...@@ -34,7 +34,7 @@ export const mockData: LLMNodeType = { ...@@ -34,7 +34,7 @@ export const mockData: LLMNodeType = {
}, },
context: { context: {
enabled: false, enabled: false,
size: 0, variable_selector: ['aaa', 'name'],
}, },
vision: { vision: {
enabled: false, enabled: false,
......
import type { FC } from 'react' import type { FC } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import MemoryConfig from '../_base/components/memory-config' import MemoryConfig from '../_base/components/memory-config'
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
import useConfig from './use-config' import useConfig from './use-config'
import { mockData } from './mock' import { mockData } from './mock'
import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list' import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list'
...@@ -8,7 +9,6 @@ import Field from '@/app/components/workflow/nodes/_base/components/field' ...@@ -8,7 +9,6 @@ import Field from '@/app/components/workflow/nodes/_base/components/field'
import AddButton from '@/app/components/base/button/add-button' import AddButton from '@/app/components/base/button/add-button'
import Split from '@/app/components/workflow/nodes/_base/components/split' 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 ModelParameterModal from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal'
import Switch from '@/app/components/base/switch'
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars' import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
const i18nPrefix = 'workflow.nodes.llm' const i18nPrefix = 'workflow.nodes.llm'
...@@ -23,7 +23,7 @@ const Panel: FC = () => { ...@@ -23,7 +23,7 @@ const Panel: FC = () => {
handleCompletionParamsChange, handleCompletionParamsChange,
handleVarListChange, handleVarListChange,
handleAddVariable, handleAddVariable,
toggleContextEnabled, handleContextVarChange,
handleMemoryChange, handleMemoryChange,
} = useConfig(mockData) } = useConfig(mockData)
const model = inputs.model const model = inputs.model
...@@ -63,21 +63,18 @@ const Panel: FC = () => { ...@@ -63,21 +63,18 @@ const Panel: FC = () => {
/> />
</Field> </Field>
{/* knowledge */}
<Field <Field
title={t(`${i18nPrefix}.context`)} title={t(`${i18nPrefix}.context`)}
operations={ tooltip={t(`${i18nPrefix}.contextTooltip`)!}
<Switch
defaultValue={inputs.context.enabled}
onChange={toggleContextEnabled}
size='md'
/>
}
> >
{inputs.context.enabled <VarReferencePicker
? ( readonly={readOnly}
<div>Context</div> isShowNodeName
) value={inputs.context.variable_selector}
: null} onChange={handleContextVarChange}
/>
</Field> </Field>
{/* Prompt */} {/* Prompt */}
......
...@@ -8,7 +8,7 @@ export type LLMNodeType = CommonNodeType & { ...@@ -8,7 +8,7 @@ export type LLMNodeType = CommonNodeType & {
memory: Memory memory: Memory
context: { context: {
enabled: boolean enabled: boolean
size: number variable_selector: ValueSelector
} }
vision: { vision: {
enabled: boolean enabled: boolean
......
import { useCallback, useState } from 'react' import { useCallback, useState } from 'react'
import produce from 'immer' import produce from 'immer'
import useVarList from '../_base/hooks/use-var-list' import useVarList from '../_base/hooks/use-var-list'
import type { Memory } from '../../types' import type { Memory, ValueSelector } from '../../types'
import type { LLMNodeType } from './types' import type { LLMNodeType } from './types'
const useConfig = (initInputs: LLMNodeType) => { const useConfig = (initInputs: LLMNodeType) => {
...@@ -31,9 +31,9 @@ const useConfig = (initInputs: LLMNodeType) => { ...@@ -31,9 +31,9 @@ const useConfig = (initInputs: LLMNodeType) => {
}) })
// context // context
const toggleContextEnabled = useCallback(() => { const handleContextVarChange = useCallback((newVar: ValueSelector) => {
const newInputs = produce(inputs, (draft) => { const newInputs = produce(inputs, (draft) => {
draft.context.enabled = !draft.context.enabled draft.context.variable_selector = newVar
}) })
setInputs(newInputs) setInputs(newInputs)
}, [inputs, setInputs]) }, [inputs, setInputs])
...@@ -51,7 +51,7 @@ const useConfig = (initInputs: LLMNodeType) => { ...@@ -51,7 +51,7 @@ const useConfig = (initInputs: LLMNodeType) => {
handleCompletionParamsChange, handleCompletionParamsChange,
handleVarListChange, handleVarListChange,
handleAddVariable, handleAddVariable,
toggleContextEnabled, handleContextVarChange,
handleMemoryChange, handleMemoryChange,
} }
} }
......
...@@ -47,6 +47,7 @@ const translation = { ...@@ -47,6 +47,7 @@ const translation = {
model: 'model', model: 'model',
variables: 'variables', variables: 'variables',
context: 'context', context: 'context',
contextTooltip: 'You can import Knowledge as context',
prompt: 'prompt', prompt: 'prompt',
vision: 'vision', vision: 'vision',
outputVars: { outputVars: {
......
...@@ -14,6 +14,7 @@ const translation = { ...@@ -14,6 +14,7 @@ const translation = {
}, },
start: { start: {
required: '必填', required: '必填',
inputField: '输入字段',
builtInVar: '内置变量', builtInVar: '内置变量',
outputVars: { outputVars: {
query: '用户输入', query: '用户输入',
...@@ -46,6 +47,7 @@ const translation = { ...@@ -46,6 +47,7 @@ const translation = {
model: '模型', model: '模型',
variables: '变量', variables: '变量',
context: '上下文', context: '上下文',
contextTooltip: '您可以导入知识库作为上下文',
prompt: '提示词', prompt: '提示词',
vision: '视觉', vision: '视觉',
outputVars: { outputVars: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment