chore: gen template

feat/enchance-prompt-and-code-fe
Joel 7 months ago
parent f438af1aa1
commit 534ece0ad0

@ -40,6 +40,7 @@ import Result from './result'
import useGenData from './use-gen-data'
import IdeaOutput from './idea-output'
import ResPlaceholder from './res-placeholder'
import { useGenerateRuleTemplate } from '@/service/use-apps'
const i18nPrefix = 'appDebug.generate'
export type IGetAutomaticResProps = {
@ -142,6 +143,15 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
setEditorKey(`${flowId}-${Date.now()}`)
}
}, [t])
const { data: instructionTemplate } = useGenerateRuleTemplate(GeneratorType.prompt)
useEffect(() => {
if (!instruction && instructionTemplate) {
setInstruction(instructionTemplate.data)
setEditorKey(`${flowId}-${Date.now()}`)
}
}, [instructionTemplate])
const isValid = () => {
if (instruction.trim() === '') {
Toast.notify({

@ -24,6 +24,7 @@ import InstructionEditor from '../automatic/instruction-editor-in-workflow'
import useGenData from '../automatic/use-gen-data'
import Result from '../automatic/result'
import ResPlaceholder from '../automatic/res-placeholder'
import { useGenerateRuleTemplate } from '@/service/use-apps'
const i18nPrefix = 'appDebug.generate'
export type IGetCodeGeneratorResProps = {
@ -79,6 +80,14 @@ export const GetCodeGeneratorResModal: FC<IGetCodeGeneratorResProps> = (
const { addVersion, current, currentVersionIndex, setCurrentVersionIndex, versions } = useGenData({
storageKey,
})
const [editorKey, setEditorKey] = useState(`${flowId}-0`)
const { data: instructionTemplate } = useGenerateRuleTemplate(GeneratorType.code)
useEffect(() => {
if (!instruction && instructionTemplate) {
setInstruction(instructionTemplate.data)
setEditorKey(`${flowId}-${Date.now()}`)
}
}, [instructionTemplate])
const isValid = () => {
if (instruction.trim() === '') {
@ -211,6 +220,7 @@ export const GetCodeGeneratorResModal: FC<IGetCodeGeneratorResProps> = (
<div className='text-[0px]'>
<div className='system-sm-semibold-uppercase mb-1.5 text-text-secondary'>{t('appDebug.codegen.instruction')}</div>
<InstructionEditor
editorKey={editorKey}
value={instruction}
onChange={setInstruction}
nodeId={nodeId}

@ -91,11 +91,6 @@ export const generateRule = (body: Record<string, any>) => {
body,
})
}
export const generateRuleCode = (body: Record<string, any>) => {
return post<CodeGenRes>('/rule-code-generate', {
body,
})
}
export const fetchModelParams = (providerName: string, modelId: string) => {
return get(`workspaces/current/model-providers/${providerName}/models/parameter-rules`, {

@ -1,8 +1,9 @@
import { get } from './base'
import { get, post } from './base'
import type { App } from '@/types/app'
import type { AppListResponse } from '@/models/app'
import { useInvalid } from './use-base'
import { useQuery } from '@tanstack/react-query'
import type { GeneratorType } from '@/app/components/app/configuration/config/automatic/types'
const NAME_SPACE = 'apps'
@ -25,3 +26,15 @@ export const useAppDetail = (appID: string) => {
queryFn: () => get<App>(`/apps/${appID}`),
})
}
export const useGenerateRuleTemplate = (type: GeneratorType) => {
return useQuery({
queryKey: [NAME_SPACE, 'generate-rule-template', type],
queryFn: () => post<{ data: string }>('instruction-generate/template', {
body: {
type,
},
}),
retry: 0,
})
}

Loading…
Cancel
Save