Revert "chore: improve prompt auto generator" (#6556)

This commit is contained in:
Joel
2024-07-23 13:35:35 +08:00
committed by GitHub
parent d726473c6d
commit 155e708540
20 changed files with 237 additions and 454 deletions

View File

@@ -1,12 +1,11 @@
'use client'
import type { FC } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import React, { useEffect, useState } from 'react'
import { uniqueId } from 'lodash-es'
import { useTranslation } from 'react-i18next'
import { RiQuestionLine } from '@remixicon/react'
import type { PromptItem, Variable } from '../../../types'
import { EditionType } from '../../../types'
import { useWorkflowStore } from '../../../store'
import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor'
import TypeSelector from '@/app/components/workflow/nodes/_base/components/selector'
import TooltipPlus from '@/app/components/base/tooltip-plus'
@@ -79,20 +78,11 @@ const ConfigPromptItem: FC<Props> = ({
handleAddVariable,
}) => {
const { t } = useTranslation()
const workflowStore = useWorkflowStore()
const {
setControlPromptEditorRerenderKey,
} = workflowStore.getState()
const [instanceId, setInstanceId] = useState(uniqueId())
useEffect(() => {
setInstanceId(`${id}-${uniqueId()}`)
}, [id])
const handleGenerated = useCallback((prompt: string) => {
onPromptChange(prompt)
setTimeout(() => setControlPromptEditorRerenderKey(Date.now()))
}, [onPromptChange, setControlPromptEditorRerenderKey])
return (
<Editor
className={className}
@@ -136,8 +126,6 @@ const ConfigPromptItem: FC<Props> = ({
hasSetBlockStatus={hasSetBlockStatus}
nodesOutputVars={availableVars}
availableNodes={availableNodes}
isSupportPromptGenerator={payload.role === PromptRole.system}
onGenerated={handleGenerated}
isSupportJinja
editionType={payload.edition_type}
onEditionTypeChange={onEditionTypeChange}

View File

@@ -8,7 +8,6 @@ import { v4 as uuid4 } from 'uuid'
import type { PromptItem, ValueSelector, Var, Variable } from '../../../types'
import { EditionType, PromptRole } from '../../../types'
import useAvailableVarList from '../../_base/hooks/use-available-var-list'
import { useWorkflowStore } from '../../../store'
import ConfigPromptItem from './config-prompt-item'
import cn from '@/utils/classnames'
import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor'
@@ -49,10 +48,6 @@ const ConfigPrompt: FC<Props> = ({
handleAddVariable,
}) => {
const { t } = useTranslation()
const workflowStore = useWorkflowStore()
const {
setControlPromptEditorRerenderKey,
} = workflowStore.getState()
const payloadWithIds = (isChatModel && Array.isArray(payload))
? payload.map((item) => {
const id = uuid4()
@@ -129,11 +124,6 @@ const ConfigPrompt: FC<Props> = ({
onChange(newPrompt)
}, [onChange, payload])
const handleGenerated = useCallback((prompt: string) => {
handleCompletionPromptChange(prompt)
setTimeout(() => setControlPromptEditorRerenderKey(Date.now()))
}, [handleCompletionPromptChange, setControlPromptEditorRerenderKey])
const handleCompletionEditionTypeChange = useCallback((editionType: EditionType) => {
const newPrompt = produce(payload as PromptItem, (draft) => {
draft.edition_type = editionType
@@ -201,8 +191,10 @@ const ConfigPrompt: FC<Props> = ({
handleAddVariable={handleAddVariable}
/>
</div>
)
})
}
</ReactSortable>
</div>
@@ -227,13 +219,11 @@ const ConfigPrompt: FC<Props> = ({
hasSetBlockStatus={hasSetBlockStatus}
nodesOutputVars={availableVars}
availableNodes={availableNodesWithParent}
isSupportPromptGenerator
isSupportJinja
editionType={(payload as PromptItem).edition_type}
varList={varList}
onEditionTypeChange={handleCompletionEditionTypeChange}
handleAddVariable={handleAddVariable}
onGenerated={handleGenerated}
/>
</div>
)}

View File

@@ -1,42 +0,0 @@
'use client'
import type { FC } from 'react'
import React, { useCallback } from 'react'
import { useBoolean } from 'ahooks'
import cn from 'classnames'
import { Generator } from '@/app/components/base/icons/src/vender/other'
import GetAutomaticResModal from '@/app/components/app/configuration/config/automatic/get-automatic-res'
import { AppType } from '@/types/app'
import type { AutomaticRes } from '@/service/debug'
type Props = {
className?: string
onGenerated?: (prompt: string) => void
}
const PromptGeneratorBtn: FC<Props> = ({
className,
onGenerated,
}) => {
const [showAutomatic, { setTrue: showAutomaticTrue, setFalse: showAutomaticFalse }] = useBoolean(false)
const handleAutomaticRes = useCallback((res: AutomaticRes) => {
onGenerated?.(res.prompt)
showAutomaticFalse()
}, [onGenerated, showAutomaticFalse])
return (
<div className={cn(className)}>
<div className='p-[5px] rounded-md hover:bg-[#155EEF]/8 cursor-pointer' onClick={showAutomaticTrue}>
<Generator className='w-3.5 h-3.5 text-primary-600' />
</div>
{showAutomatic && (
<GetAutomaticResModal
mode={AppType.chat}
isShow={showAutomatic}
onClose={showAutomaticFalse}
onFinished={handleAutomaticRes}
isInLLMNode
/>
)}
</div>
)
}
export default React.memo(PromptGeneratorBtn)