mirror of https://github.com/langgenius/dify.git
feat: choose context var
This commit is contained in:
parent
0acb2db9b6
commit
6f6f032244
|
|
@ -6,7 +6,7 @@ import Workflow from '@/app/components/workflow'
|
|||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
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.VariableAssigner/* 11 */, BlockEnum.End/* 12 */,
|
||||
].map((item, i) => ({
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ export const mockData: LLMNodeType = {
|
|||
},
|
||||
context: {
|
||||
enabled: false,
|
||||
size: 0,
|
||||
variable_selector: ['aaa', 'name'],
|
||||
},
|
||||
vision: {
|
||||
enabled: false,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { FC } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import MemoryConfig from '../_base/components/memory-config'
|
||||
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
|
||||
import useConfig from './use-config'
|
||||
import { mockData } from './mock'
|
||||
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'
|
|||
import AddButton from '@/app/components/base/button/add-button'
|
||||
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 Switch from '@/app/components/base/switch'
|
||||
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
|
||||
|
||||
const i18nPrefix = 'workflow.nodes.llm'
|
||||
|
|
@ -23,7 +23,7 @@ const Panel: FC = () => {
|
|||
handleCompletionParamsChange,
|
||||
handleVarListChange,
|
||||
handleAddVariable,
|
||||
toggleContextEnabled,
|
||||
handleContextVarChange,
|
||||
handleMemoryChange,
|
||||
} = useConfig(mockData)
|
||||
const model = inputs.model
|
||||
|
|
@ -63,21 +63,18 @@ const Panel: FC = () => {
|
|||
/>
|
||||
</Field>
|
||||
|
||||
{/* knowledge */}
|
||||
<Field
|
||||
title={t(`${i18nPrefix}.context`)}
|
||||
operations={
|
||||
<Switch
|
||||
defaultValue={inputs.context.enabled}
|
||||
onChange={toggleContextEnabled}
|
||||
size='md'
|
||||
/>
|
||||
}
|
||||
tooltip={t(`${i18nPrefix}.contextTooltip`)!}
|
||||
>
|
||||
{inputs.context.enabled
|
||||
? (
|
||||
<div>Context</div>
|
||||
)
|
||||
: null}
|
||||
<VarReferencePicker
|
||||
readonly={readOnly}
|
||||
isShowNodeName
|
||||
value={inputs.context.variable_selector}
|
||||
onChange={handleContextVarChange}
|
||||
/>
|
||||
|
||||
</Field>
|
||||
|
||||
{/* Prompt */}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export type LLMNodeType = CommonNodeType & {
|
|||
memory: Memory
|
||||
context: {
|
||||
enabled: boolean
|
||||
size: number
|
||||
variable_selector: ValueSelector
|
||||
}
|
||||
vision: {
|
||||
enabled: boolean
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useCallback, useState } from 'react'
|
||||
import produce from 'immer'
|
||||
import useVarList from '../_base/hooks/use-var-list'
|
||||
import type { Memory } from '../../types'
|
||||
import type { Memory, ValueSelector } from '../../types'
|
||||
import type { LLMNodeType } from './types'
|
||||
|
||||
const useConfig = (initInputs: LLMNodeType) => {
|
||||
|
|
@ -31,9 +31,9 @@ const useConfig = (initInputs: LLMNodeType) => {
|
|||
})
|
||||
|
||||
// context
|
||||
const toggleContextEnabled = useCallback(() => {
|
||||
const handleContextVarChange = useCallback((newVar: ValueSelector) => {
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.context.enabled = !draft.context.enabled
|
||||
draft.context.variable_selector = newVar
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [inputs, setInputs])
|
||||
|
|
@ -51,7 +51,7 @@ const useConfig = (initInputs: LLMNodeType) => {
|
|||
handleCompletionParamsChange,
|
||||
handleVarListChange,
|
||||
handleAddVariable,
|
||||
toggleContextEnabled,
|
||||
handleContextVarChange,
|
||||
handleMemoryChange,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ const translation = {
|
|||
model: 'model',
|
||||
variables: 'variables',
|
||||
context: 'context',
|
||||
contextTooltip: 'You can import Knowledge as context',
|
||||
prompt: 'prompt',
|
||||
vision: 'vision',
|
||||
outputVars: {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ const translation = {
|
|||
},
|
||||
start: {
|
||||
required: '必填',
|
||||
inputField: '输入字段',
|
||||
builtInVar: '内置变量',
|
||||
outputVars: {
|
||||
query: '用户输入',
|
||||
|
|
@ -46,6 +47,7 @@ const translation = {
|
|||
model: '模型',
|
||||
variables: '变量',
|
||||
context: '上下文',
|
||||
contextTooltip: '您可以导入知识库作为上下文',
|
||||
prompt: '提示词',
|
||||
vision: '视觉',
|
||||
outputVars: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue