Ver código fonte

fix: prompt-editor regex.lastIndex needed to reset (#9097)

Co-authored-by: Chen(MAC) <chenchen404@outlook.com>
tags/0.9.2
Pika 1 ano atrás
pai
commit
0540995e5c
Nenhuma conta vinculada ao e-mail do autor do commit

+ 3
- 2
web/app/components/base/prompt-editor/plugins/workflow-variable-block/workflow-variable-block-replacement-block.tsx Ver arquivo

import { CustomTextNode } from '../custom-text/node' import { CustomTextNode } from '../custom-text/node'
import { $createWorkflowVariableBlockNode } from './node' import { $createWorkflowVariableBlockNode } from './node'
import { WorkflowVariableBlockNode } from './index' import { WorkflowVariableBlockNode } from './index'
import { VAR_REGEX as REGEX } from '@/config'
import { VAR_REGEX as REGEX, resetReg } from '@/config'


const WorkflowVariableBlockReplacementBlock = ({ const WorkflowVariableBlockReplacementBlock = ({
workflowNodesMap, workflowNodesMap,
}, []) }, [])


const transformListener = useCallback((textNode: any) => { const transformListener = useCallback((textNode: any) => {
resetReg()
return decoratorTransform(textNode, getMatch, createWorkflowVariableBlockNode) return decoratorTransform(textNode, getMatch, createWorkflowVariableBlockNode)
}, [createWorkflowVariableBlockNode, getMatch]) }, [createWorkflowVariableBlockNode, getMatch])


useEffect(() => { useEffect(() => {
REGEX.lastIndex = 0
resetReg()
return mergeRegister( return mergeRegister(
editor.registerNodeTransform(CustomTextNode, transformListener), editor.registerNodeTransform(CustomTextNode, transformListener),
) )

+ 12
- 10
web/config/index.ts Ver arquivo

} }


export const DEFAULT_AGENT_PROMPT = { export const DEFAULT_AGENT_PROMPT = {
chat: `Respond to the human as helpfully and accurately as possible.
chat: `Respond to the human as helpfully and accurately as possible.


{{instruction}} {{instruction}}
You have access to the following tools: You have access to the following tools:
{{tools}} {{tools}}
Use a json blob to specify a tool by providing an {{TOOL_NAME_KEY}} key (tool name) and an {{ACTION_INPUT_KEY}} key (tool input). Use a json blob to specify a tool by providing an {{TOOL_NAME_KEY}} key (tool name) and an {{ACTION_INPUT_KEY}} key (tool input).
Valid "{{TOOL_NAME_KEY}}" values: "Final Answer" or {{tool_names}} Valid "{{TOOL_NAME_KEY}}" values: "Final Answer" or {{tool_names}}
Provide only ONE action per $JSON_BLOB, as shown: Provide only ONE action per $JSON_BLOB, as shown:
\`\`\` \`\`\`
{ {
"{{TOOL_NAME_KEY}}": $TOOL_NAME, "{{TOOL_NAME_KEY}}": $TOOL_NAME,
"{{ACTION_INPUT_KEY}}": $ACTION_INPUT "{{ACTION_INPUT_KEY}}": $ACTION_INPUT
} }
\`\`\` \`\`\`
Follow this format: Follow this format:
Question: input question to answer Question: input question to answer
Thought: consider previous and subsequent steps Thought: consider previous and subsequent steps
Action: Action:
"{{ACTION_INPUT_KEY}}": "Final response to human" "{{ACTION_INPUT_KEY}}": "Final response to human"
} }
\`\`\` \`\`\`
Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:\`\`\`$JSON_BLOB\`\`\`then Observation:.`, Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:\`\`\`$JSON_BLOB\`\`\`then Observation:.`,
completion: ` completion: `
Respond to the human as helpfully and accurately as possible.
Respond to the human as helpfully and accurately as possible.


{{instruction}} {{instruction}}




export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_][a-zA-Z0-9_]{0,29}){1,10}#)\}\}/gi export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_][a-zA-Z0-9_]{0,29}){1,10}#)\}\}/gi


export const resetReg = () => VAR_REGEX.lastIndex = 0

export let textGenerationTimeoutMs = 60000 export let textGenerationTimeoutMs = 60000


if (process.env.NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS && process.env.NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS !== '') if (process.env.NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS && process.env.NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS !== '')

Carregando…
Cancelar
Salvar