feat: call gen api

feat/enchance-prompt-and-code-fe
Joel 10 months ago
parent 945a424fa8
commit f14678a0d8

@ -136,8 +136,9 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
}, },
] ]
const [instruction, setInstruction] = useState<string>('') const [instruction, setInstruction] = useState<string>('The travel plan to Anshun of Guizhou Province in China') // TODO: test value
const [ideaOutput, setIdeaOutput] = useState<string>('') const [ideaOutput, setIdeaOutput] = useState<string>('use json format to output the result. Content in result uses Chinese. Format: {"summary: "summary content", "result": "result content"}')
const [currentPrompt, setCurrentPrompt] = useState<string>('')
const [isFoldIdeaOutput, { const [isFoldIdeaOutput, {
toggle: toggleFoldIdeaOutput, toggle: toggleFoldIdeaOutput,
}] = useBoolean(true) }] = useBoolean(true)
@ -226,7 +227,11 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
setLoadingTrue() setLoadingTrue()
try { try {
const { error, ...res } = await generateRule({ const { error, ...res } = await generateRule({
flow_id: flowId,
node_id: nodeId,
current: currentPrompt,
instruction, instruction,
idea_output: ideaOutput,
model_config: model, model_config: model,
}) })
setRes(res) setRes(res)

@ -5,6 +5,7 @@ export const useConfigsMap = () => {
const appId = useStore(s => s.appId) const appId = useStore(s => s.appId)
return useMemo(() => { return useMemo(() => {
return { return {
flowId: appId,
conversationVarsUrl: `apps/${appId}/workflows/draft/conversation-variables`, conversationVarsUrl: `apps/${appId}/workflows/draft/conversation-variables`,
systemVarsUrl: `apps/${appId}/workflows/draft/system-variables`, systemVarsUrl: `apps/${appId}/workflows/draft/system-variables`,
} }

@ -35,7 +35,6 @@ export const useWorkflowRun = () => {
const invalidAllLastRun = useInvalidAllLastRun(appId as string) const invalidAllLastRun = useInvalidAllLastRun(appId as string)
const configsMap = useConfigsMap() const configsMap = useConfigsMap()
const { fetchInspectVars } = useSetWorkflowVarsWithValue({ const { fetchInspectVars } = useSetWorkflowVarsWithValue({
flowId: appId as string,
...configsMap, ...configsMap,
}) })

@ -49,6 +49,7 @@ type CommonHooksFnMap = {
resetConversationVar: (varId: string) => Promise<void> resetConversationVar: (varId: string) => Promise<void>
invalidateConversationVarValues: () => void invalidateConversationVarValues: () => void
configsMap?: { configsMap?: {
flowId: string
conversationVarsUrl: string conversationVarsUrl: string
systemVarsUrl: string systemVarsUrl: string
} }

@ -87,6 +87,7 @@ export const AgentStrategy = memo((props: AgentStrategyProps) => {
headerClassName='bg-transparent px-0 text-text-secondary system-sm-semibold-uppercase' headerClassName='bg-transparent px-0 text-text-secondary system-sm-semibold-uppercase'
containerBackgroundClassName='bg-transparent' containerBackgroundClassName='bg-transparent'
gradientBorder={false} gradientBorder={false}
nodeId={nodeId}
isSupportPromptGenerator={!!def.auto_generate?.type} isSupportPromptGenerator={!!def.auto_generate?.type}
titleTooltip={schema.tooltip && renderI18nObject(schema.tooltip)} titleTooltip={schema.tooltip && renderI18nObject(schema.tooltip)}
editorContainerClassName='px-0' editorContainerClassName='px-0'

@ -41,6 +41,7 @@ type Props = {
className?: string className?: string
headerClassName?: string headerClassName?: string
instanceId?: string instanceId?: string
nodeId?: string
title: string | React.JSX.Element title: string | React.JSX.Element
value: string value: string
onChange: (value: string) => void onChange: (value: string) => void
@ -83,6 +84,7 @@ const Editor: FC<Props> = ({
className, className,
headerClassName, headerClassName,
instanceId, instanceId,
nodeId,
title, title,
value, value,
onChange, onChange,
@ -160,6 +162,7 @@ const Editor: FC<Props> = ({
<div className='text-xs font-medium leading-[18px] text-text-tertiary'>{value?.length || 0}</div> <div className='text-xs font-medium leading-[18px] text-text-tertiary'>{value?.length || 0}</div>
{isSupportPromptGenerator && ( {isSupportPromptGenerator && (
<PromptGeneratorBtn <PromptGeneratorBtn
nodeId={nodeId!}
className='ml-[5px]' className='ml-[5px]'
onGenerated={onGenerated} onGenerated={onGenerated}
modelConfig={modelConfig} modelConfig={modelConfig}

@ -136,6 +136,7 @@ const ConfigPromptItem: FC<Props> = ({
hasSetBlockStatus={hasSetBlockStatus} hasSetBlockStatus={hasSetBlockStatus}
nodesOutputVars={availableVars} nodesOutputVars={availableVars}
availableNodes={availableNodes} availableNodes={availableNodes}
nodeId={id}
isSupportPromptGenerator={payload.role === PromptRole.system} isSupportPromptGenerator={payload.role === PromptRole.system}
onGenerated={handleGenerated} onGenerated={handleGenerated}
modelConfig={modelConfig} modelConfig={modelConfig}

@ -10,11 +10,13 @@ import { AppType } from '@/types/app'
import type { AutomaticRes } from '@/service/debug' import type { AutomaticRes } from '@/service/debug'
import type { ModelConfig, Node, NodeOutPutVar } from '@/app/components/workflow/types' import type { ModelConfig, Node, NodeOutPutVar } from '@/app/components/workflow/types'
import { GeneratorType } from '@/app/components/app/configuration/config/automatic/types' import { GeneratorType } from '@/app/components/app/configuration/config/automatic/types'
import { useHooksStore } from '../../../hooks-store'
type Props = { type Props = {
className?: string className?: string
onGenerated?: (prompt: string) => void onGenerated?: (prompt: string) => void
modelConfig?: ModelConfig modelConfig?: ModelConfig
nodeId: string
nodesOutputVars?: NodeOutPutVar[] nodesOutputVars?: NodeOutPutVar[]
availableNodes?: Node[] availableNodes?: Node[]
} }
@ -22,6 +24,7 @@ type Props = {
const PromptGeneratorBtn: FC<Props> = ({ const PromptGeneratorBtn: FC<Props> = ({
className, className,
onGenerated, onGenerated,
nodeId,
nodesOutputVars, nodesOutputVars,
availableNodes, availableNodes,
}) => { }) => {
@ -30,6 +33,7 @@ const PromptGeneratorBtn: FC<Props> = ({
onGenerated?.(res.prompt) onGenerated?.(res.prompt)
showAutomaticFalse() showAutomaticFalse()
}, [onGenerated, showAutomaticFalse]) }, [onGenerated, showAutomaticFalse])
const configsMap = useHooksStore(s => s.configsMap)
return ( return (
<div className={cn(className)}> <div className={cn(className)}>
<ActionButton <ActionButton
@ -46,6 +50,8 @@ const PromptGeneratorBtn: FC<Props> = ({
generatorType={GeneratorType.prompt} generatorType={GeneratorType.prompt}
nodesOutputVars={nodesOutputVars} nodesOutputVars={nodesOutputVars}
availableNodes={availableNodes} availableNodes={availableNodes}
flowId={configsMap?.flowId || ''}
nodeId={nodeId}
/> />
)} )}
</div> </div>

@ -72,7 +72,7 @@ export const fetchConversationMessages = (appId: string, conversation_id: string
} }
export const generateRule = (body: Record<string, any>) => { export const generateRule = (body: Record<string, any>) => {
return post<AutomaticRes>('/rule-generate', { return post<AutomaticRes>('/instruction-generate', {
body, body,
}) })
} }

Loading…
Cancel
Save