feat: instruction template

feat/enchance-prompt-and-code-fe
Joel 7 months ago
parent 71d08d0580
commit ab45f3ce26

@ -276,6 +276,7 @@ const Prompt: FC<ISimplePromptInput> = ({
isShow={showAutomatic}
onClose={showAutomaticFalse}
onFinished={handleAutomaticRes}
currentPrompt={promptTemplate}
isBasicMode
/>
)}

@ -144,7 +144,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
}
}, [t])
const { data: instructionTemplate } = useGenerateRuleTemplate(GeneratorType.prompt)
const { data: instructionTemplate } = useGenerateRuleTemplate(GeneratorType.prompt, isBasicMode)
useEffect(() => {
if (!instruction && instructionTemplate) {
setInstruction(instructionTemplate.data)
@ -337,6 +337,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
availableVars={[]}
availableNodes={[]}
isShowCurrentBlock={!!currentPrompt}
isShowLastRunBlock={false}
/>
) : (
<InstructionEditorInWorkflow

@ -1,13 +1,13 @@
'use client'
import type { FC } from 'react'
import React, { useCallback } from 'react'
import React, { useCallback, useMemo } from 'react'
import type { GeneratorType } from './types'
import type { ValueSelector, Var } from '@/app/components/workflow/types'
import { VarType } from '@/app/components/workflow/types'
import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list'
import InstructionEditor from './instruction-editor'
import { useWorkflowVariableType } from '@/app/components/workflow/hooks'
import { useWorkflowStore } from '@/app/components/workflow/store'
import { useStore, useWorkflowStore } from '@/app/components/workflow/store'
type Props = {
nodeId: string
@ -27,7 +27,10 @@ const InstructionEditorInWorkflow: FC<Props> = ({
isShowCurrentBlock,
}) => {
const workflowStore = useWorkflowStore()
const nodesWithInspectVars = useStore(s => s.nodesWithInspectVars)
const isShowLastRunBlock = useMemo(() => {
return !!nodesWithInspectVars.find(node => node.nodeId === nodeId)
}, [nodesWithInspectVars])
const filterVar = useCallback((payload: Var, selector: ValueSelector) => {
const { nodesWithInspectVars } = workflowStore.getState()
const nodeId = selector?.[0]
@ -52,6 +55,7 @@ const InstructionEditorInWorkflow: FC<Props> = ({
availableNodes={availableNodes}
getVarType={getVarType}
isShowCurrentBlock={isShowCurrentBlock}
isShowLastRunBlock
/>
)
}

@ -21,6 +21,7 @@ type Props = {
valueSelector: ValueSelector,
}) => Type
isShowCurrentBlock: boolean
isShowLastRunBlock: boolean
}
const i18nPrefix = 'appDebug.generate'
@ -34,6 +35,7 @@ const InstructionEditor: FC<Props> = ({
availableNodes,
getVarType = () => Type.string,
isShowCurrentBlock,
isShowLastRunBlock,
}) => {
const { t } = useTranslation()
const isBasicMode = !!getVarType
@ -88,7 +90,7 @@ const InstructionEditor: FC<Props> = ({
show: isCode,
}}
lastRunBlock={{
show: true,
show: isShowLastRunBlock,
}}
onChange={onChange}
editable

@ -416,7 +416,7 @@ const VarReferenceVars: FC<Props> = ({
</div>))
}
</div>
: <div className='pl-3 text-xs font-medium uppercase leading-[18px] text-gray-500'>{t('workflow.common.noVar')}</div>}
: <div className='mt-2 pl-3 text-xs font-medium uppercase leading-[18px] text-gray-500'>{t('workflow.common.noVar')}</div>}
</>
)
}

@ -27,7 +27,7 @@ export const useAppDetail = (appID: string) => {
})
}
export const useGenerateRuleTemplate = (type: GeneratorType) => {
export const useGenerateRuleTemplate = (type: GeneratorType, disabled?: boolean) => {
return useQuery({
queryKey: [NAME_SPACE, 'generate-rule-template', type],
queryFn: () => post<{ data: string }>('instruction-generate/template', {
@ -35,6 +35,7 @@ export const useGenerateRuleTemplate = (type: GeneratorType) => {
type,
},
}),
enabled: !disabled,
retry: 0,
})
}

Loading…
Cancel
Save