chore: can set to value

feat/enchance-prompt-and-code-fe
Joel 10 months ago
parent a85908386e
commit ed737beb4a

@ -165,17 +165,17 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
} }
const [isLoading, { setTrue: setLoadingTrue, setFalse: setLoadingFalse }] = useBoolean(false) const [isLoading, { setTrue: setLoadingTrue, setFalse: setLoadingFalse }] = useBoolean(false)
const storageKey = `${flowId}${isBasicMode ? '' : `-${nodeId}`}` const storageKey = `${flowId}${isBasicMode ? '' : `-${nodeId}`}`
const { versions, addVersion, current } = useGenData({ const { addVersion, current, currentVersionIndex, setCurrentVersionIndex, versions } = useGenData({
storageKey, storageKey,
}) })
useEffect(() => { // useEffect(() => {
// if (!versions.length) { // // if (!versions.length) {
addVersion({ // addVersion({
modified: 'ddd', // modified: 'ddd',
}) // })
// } // // }
}, []) // }, [])
useEffect(() => { useEffect(() => {
if (defaultModel) { if (defaultModel) {
@ -387,7 +387,10 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
{ {
<div className='h-full w-0 grow p-6 pb-0'> <div className='h-full w-0 grow p-6 pb-0'>
<Result <Result
storageKey={storageKey} current={current!}
currentVersionIndex={currentVersionIndex || 0}
setCurrentVersionIndex={setCurrentVersionIndex}
versions={versions || []}
onApply={showConfirmOverwrite} onApply={showConfirmOverwrite}
generatorType={generatorType} generatorType={generatorType}
/> />

@ -5,25 +5,28 @@ import { useTranslation } from 'react-i18next'
import { GeneratorType } from './types' import { GeneratorType } from './types'
import PromptToast from './prompt-toast' import PromptToast from './prompt-toast'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import useGenData from './use-gen-data'
import VersionSelector from './version-selector' import VersionSelector from './version-selector'
import type { GenRes } from '@/service/debug'
type Props = { type Props = {
storageKey: string current: GenRes
currentVersionIndex: number
setCurrentVersionIndex: (index: number) => void
versions: GenRes[]
onApply: () => void onApply: () => void
generatorType: GeneratorType generatorType: GeneratorType
} }
const Result: FC<Props> = ({ const Result: FC<Props> = ({
storageKey, current,
currentVersionIndex,
setCurrentVersionIndex,
versions,
onApply, onApply,
generatorType, generatorType,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const isGeneratorPrompt = generatorType === GeneratorType.prompt const isGeneratorPrompt = generatorType === GeneratorType.prompt
const { current, currentVersionIndex, setCurrentVersionIndex, versions } = useGenData({
storageKey,
})
return ( return (
<div> <div>

@ -15,14 +15,14 @@ const useGenData = ({ storageKey }: Params) => {
defaultValue: 0, defaultValue: 0,
}) })
const current = versions[currentVersionIndex] const current = versions?.[currentVersionIndex || 0]
const addVersion = useCallback((version: GenRes) => { const addVersion = useCallback((version: GenRes) => {
setCurrentVersionIndex(() => versions.length) setCurrentVersionIndex(() => versions?.length || 0)
setVersions((prev) => { setVersions((prev) => {
return [...prev!, version] return [...prev!, version]
}) })
}, [setVersions, setCurrentVersionIndex, versions.length]) }, [setVersions, setCurrentVersionIndex, versions?.length])
return { return {
versions, versions,

@ -19,6 +19,7 @@ type Props = {
canNotChooseSystemRole?: boolean canNotChooseSystemRole?: boolean
readOnly: boolean readOnly: boolean
id: string id: string
nodeId: string
canRemove: boolean canRemove: boolean
isChatModel: boolean isChatModel: boolean
isChatApp: boolean isChatApp: boolean
@ -63,6 +64,7 @@ const ConfigPromptItem: FC<Props> = ({
canNotChooseSystemRole, canNotChooseSystemRole,
readOnly, readOnly,
id, id,
nodeId,
canRemove, canRemove,
handleChatModeMessageRoleChange, handleChatModeMessageRoleChange,
isChatModel, isChatModel,
@ -136,7 +138,7 @@ const ConfigPromptItem: FC<Props> = ({
hasSetBlockStatus={hasSetBlockStatus} hasSetBlockStatus={hasSetBlockStatus}
nodesOutputVars={availableVars} nodesOutputVars={availableVars}
availableNodes={availableNodes} availableNodes={availableNodes}
nodeId={id} nodeId={nodeId}
isSupportPromptGenerator={payload.role === PromptRole.system} isSupportPromptGenerator={payload.role === PromptRole.system}
onGenerated={handleGenerated} onGenerated={handleGenerated}
modelConfig={modelConfig} modelConfig={modelConfig}

@ -188,6 +188,7 @@ const ConfigPrompt: FC<Props> = ({
canRemove={payload.length > 1 && !(index === 0 && item.role === PromptRole.system)} canRemove={payload.length > 1 && !(index === 0 && item.role === PromptRole.system)}
readOnly={readOnly} readOnly={readOnly}
id={item.id!} id={item.id!}
nodeId={nodeId}
handleChatModeMessageRoleChange={handleChatModeMessageRoleChange(index)} handleChatModeMessageRoleChange={handleChatModeMessageRoleChange(index)}
isChatModel={isChatModel} isChatModel={isChatModel}
isChatApp={isChatApp} isChatApp={isChatApp}

Loading…
Cancel
Save