Commit fbcc769d authored by Joel's avatar Joel

feat: instructions

parent 65f0378e
...@@ -8,7 +8,7 @@ import { Clipboard, ClipboardCheck } from '@/app/components/base/icons/src/vende ...@@ -8,7 +8,7 @@ import { Clipboard, ClipboardCheck } from '@/app/components/base/icons/src/vende
import { Expand04 } from '@/app/components/base/icons/src/vender/solid/arrows' import { Expand04 } from '@/app/components/base/icons/src/vender/solid/arrows'
type Props = { type Props = {
className?: string className?: string
title: JSX.Element title: JSX.Element | string
headerRight?: JSX.Element headerRight?: JSX.Element
children: JSX.Element children: JSX.Element
minHeight?: number minHeight?: number
......
...@@ -7,7 +7,7 @@ import Base from './base' ...@@ -7,7 +7,7 @@ import Base from './base'
type Props = { type Props = {
value: string value: string
onChange: (value: string) => void onChange: (value: string) => void
title: JSX.Element title: JSX.Element | string
headerRight?: JSX.Element headerRight?: JSX.Element
minHeight?: number minHeight?: number
onBlur?: () => void onBlur?: () => void
......
'use client'
import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import TextEditor from '../../_base/components/editor/text-editor'
import type { Memory } from '@/app/components/workflow/types'
const i18nPrefix = 'workflow.nodes.questionClassifiers'
type Props = {
instruction: string
onInstructionChange: (instruction: string) => void
memory: Memory
}
const AdvancedSetting: FC<Props> = ({
instruction,
onInstructionChange,
memory,
}) => {
const { t } = useTranslation()
return (
<div>
<TextEditor
title={t(`${i18nPrefix}.instruction`)!}
value={instruction}
onChange={onInstructionChange}
minHeight={160}
placeholder={t(`${i18nPrefix}.instructionPlaceholder`)!}
headerRight={(
<div className='flex items-center h-full'>
<div className='text-xs font-medium text-gray-500'>{instruction.length}</div>
<div className='mx-3 h-3 w-px bg-gray-200'></div>
</div>
)}
/>
</div>
)
}
export default React.memo(AdvancedSetting)
...@@ -34,7 +34,7 @@ const ClassList: FC<Props> = ({ ...@@ -34,7 +34,7 @@ const ClassList: FC<Props> = ({
draft.push({ id: '', name: t(`${i18nPrefix}.class`) + (list.length + 1), topic: '' }) draft.push({ id: '', name: t(`${i18nPrefix}.class`) + (list.length + 1), topic: '' })
}) })
onChange(newList) onChange(newList)
}, [list, onChange]) }, [list, onChange, t])
const handleRemoveClass = useCallback((index: number) => { const handleRemoveClass = useCallback((index: number) => {
return () => { return () => {
......
...@@ -4,9 +4,9 @@ import VarReferencePicker from '../_base/components/variable/var-reference-picke ...@@ -4,9 +4,9 @@ import VarReferencePicker from '../_base/components/variable/var-reference-picke
import useConfig from './use-config' import useConfig from './use-config'
import { mockData } from './mock' import { mockData } from './mock'
import ClassList from './components/class-list' import ClassList from './components/class-list'
import AdvancedSetting from './components/advanced-setting'
import Field from '@/app/components/workflow/nodes/_base/components/field' import Field from '@/app/components/workflow/nodes/_base/components/field'
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'
const i18nPrefix = 'workflow.nodes.questionClassifiers' const i18nPrefix = 'workflow.nodes.questionClassifiers'
const Panel: FC = () => { const Panel: FC = () => {
...@@ -19,6 +19,7 @@ const Panel: FC = () => { ...@@ -19,6 +19,7 @@ const Panel: FC = () => {
handleCompletionParamsChange, handleCompletionParamsChange,
handleQueryVarChange, handleQueryVarChange,
handleTopicsChange, handleTopicsChange,
handleInstructionChange,
} = useConfig(mockData) } = useConfig(mockData)
const model = inputs.model const model = inputs.model
...@@ -60,7 +61,11 @@ const Panel: FC = () => { ...@@ -60,7 +61,11 @@ const Panel: FC = () => {
<Field <Field
title={t(`${i18nPrefix}.advancedSetting`)} title={t(`${i18nPrefix}.advancedSetting`)}
> >
advancedSetting <AdvancedSetting
instruction={inputs.instruction}
onInstructionChange={handleInstructionChange}
memory={inputs.memory}
/>
</Field> </Field>
</div> </div>
) )
......
...@@ -37,12 +37,20 @@ const useConfig = (initInputs: QuestionClassifierNodeType) => { ...@@ -37,12 +37,20 @@ const useConfig = (initInputs: QuestionClassifierNodeType) => {
setInputs(newInputs) setInputs(newInputs)
}, [inputs, setInputs]) }, [inputs, setInputs])
const handleInstructionChange = useCallback((instruction: string) => {
const newInputs = produce(inputs, (draft) => {
draft.instruction = instruction
})
setInputs(newInputs)
}, [inputs, setInputs])
return { return {
inputs, inputs,
handleModelChanged, handleModelChanged,
handleCompletionParamsChange, handleCompletionParamsChange,
handleQueryVarChange, handleQueryVarChange,
handleTopicsChange, handleTopicsChange,
handleInstructionChange,
} }
} }
......
...@@ -133,6 +133,8 @@ const translation = { ...@@ -133,6 +133,8 @@ const translation = {
advancedSetting: 'Advanced Setting', advancedSetting: 'Advanced Setting',
topicPlaceholder: 'Write your topic name', topicPlaceholder: 'Write your topic name',
addClass: 'Add Class', addClass: 'Add Class',
instruction: 'Instruction',
instructionPlaceholder: 'Write your instruction',
}, },
}, },
} }
......
...@@ -132,6 +132,8 @@ const translation = { ...@@ -132,6 +132,8 @@ const translation = {
advancedSetting: '高级设置', advancedSetting: '高级设置',
topicPlaceholder: '在这里输入你的主题内容', topicPlaceholder: '在这里输入你的主题内容',
addClass: '添加分类', addClass: '添加分类',
instruction: '指令',
instructionPlaceholder: '在这里输入你的指令',
}, },
}, },
} }
......
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