feat: mermory size config

This commit is contained in:
Joel
2024-02-29 14:50:36 +08:00
parent fbcc769d4e
commit 9e6940ed3e
8 changed files with 158 additions and 7 deletions

View File

@ -3,25 +3,27 @@ import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import TextEditor from '../../_base/components/editor/text-editor'
import MemoryConfig from '../../_base/components/memory-config'
import type { Memory } from '@/app/components/workflow/types'
const i18nPrefix = 'workflow.nodes.questionClassifiers'
type Props = {
instruction: string
onInstructionChange: (instruction: string) => void
memory: Memory
onMemoryChange: (memory: Memory) => void
}
const AdvancedSetting: FC<Props> = ({
instruction,
onInstructionChange,
memory,
onMemoryChange,
}) => {
const { t } = useTranslation()
return (
<div>
<>
<TextEditor
title={t(`${i18nPrefix}.instruction`)!}
value={instruction}
@ -35,7 +37,14 @@ const AdvancedSetting: FC<Props> = ({
</div>
)}
/>
</div>
<MemoryConfig
className='mt-4'
readonly={false}
payload={memory}
onChange={onMemoryChange}
canSetRoleName={false}
/>
</>
)
}
export default React.memo(AdvancedSetting)

View File

@ -20,6 +20,7 @@ const Panel: FC = () => {
handleQueryVarChange,
handleTopicsChange,
handleInstructionChange,
handleMemoryChange,
} = useConfig(mockData)
const model = inputs.model
@ -65,6 +66,7 @@ const Panel: FC = () => {
instruction={inputs.instruction}
onInstructionChange={handleInstructionChange}
memory={inputs.memory}
onMemoryChange={handleMemoryChange}
/>
</Field>
</div>

View File

@ -1,6 +1,6 @@
import { useCallback, useState } from 'react'
import produce from 'immer'
import type { ValueSelector } from '../../types'
import type { Memory, ValueSelector } from '../../types'
import type { QuestionClassifierNodeType } from './types'
const useConfig = (initInputs: QuestionClassifierNodeType) => {
@ -44,6 +44,13 @@ const useConfig = (initInputs: QuestionClassifierNodeType) => {
setInputs(newInputs)
}, [inputs, setInputs])
const handleMemoryChange = useCallback((memory: Memory) => {
const newInputs = produce(inputs, (draft) => {
draft.memory = memory
})
setInputs(newInputs)
}, [inputs, setInputs])
return {
inputs,
handleModelChanged,
@ -51,6 +58,7 @@ const useConfig = (initInputs: QuestionClassifierNodeType) => {
handleQueryVarChange,
handleTopicsChange,
handleInstructionChange,
handleMemoryChange,
}
}