mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 15:00:57 +03:00
@@ -7,7 +7,7 @@ import { BaseChatModel } from '@langchain/core/language_models/chat_models'
|
||||
import { ChatPromptTemplate, MessagesPlaceholder, HumanMessagePromptTemplate, PromptTemplate } from '@langchain/core/prompts'
|
||||
import { formatToOpenAIToolMessages } from 'langchain/agents/format_scratchpad/openai_tools'
|
||||
import { type ToolsAgentStep } from 'langchain/agents/openai/output_parser'
|
||||
import { getBaseClasses, handleEscapeCharacters } from '../../../src/utils'
|
||||
import { getBaseClasses, handleEscapeCharacters, removeInvalidImageMarkdown } from '../../../src/utils'
|
||||
import {
|
||||
FlowiseMemory,
|
||||
ICommonObject,
|
||||
@@ -188,6 +188,8 @@ class ToolAgent_Agents implements INode {
|
||||
output = output?.text || ''
|
||||
}
|
||||
|
||||
output = removeInvalidImageMarkdown(output)
|
||||
|
||||
// Claude 3 Opus tends to spit out <thinking>..</thinking> as well, discard that in final output
|
||||
const regexPattern: RegExp = /<thinking>[\s\S]*?<\/thinking>/
|
||||
const matches: RegExpMatchArray | null = output.match(regexPattern)
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
IStateWithMessages
|
||||
} from '../../../src/Interface'
|
||||
import { ToolCallingAgentOutputParser, AgentExecutor, SOURCE_DOCUMENTS_PREFIX, ARTIFACTS_PREFIX } from '../../../src/agents'
|
||||
import { getInputVariables, getVars, handleEscapeCharacters, prepareSandboxVars } from '../../../src/utils'
|
||||
import { getInputVariables, getVars, handleEscapeCharacters, prepareSandboxVars, removeInvalidImageMarkdown } from '../../../src/utils'
|
||||
import {
|
||||
customGet,
|
||||
getVM,
|
||||
@@ -781,9 +781,7 @@ async function agentNode(
|
||||
}
|
||||
|
||||
let outputContent = typeof result === 'string' ? result : result.content || result.output
|
||||
|
||||
// remove invalid markdown image pattern: 
|
||||
outputContent = typeof outputContent === 'string' ? outputContent.replace(/!\[.*?\]\(.*?\)/g, '') : outputContent
|
||||
outputContent = removeInvalidImageMarkdown(outputContent)
|
||||
|
||||
if (nodeData.inputs?.updateStateMemoryUI || nodeData.inputs?.updateStateMemoryCode) {
|
||||
let formattedOutput = {
|
||||
|
||||
@@ -926,3 +926,8 @@ export const mapMimeTypeToExt = (mimeType: string) => {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
// remove invalid markdown image pattern: 
|
||||
export const removeInvalidImageMarkdown = (output: string): string => {
|
||||
return typeof output === 'string' ? output.replace(/!\[.*?\]\((?!https?:\/\/).*?\)/g, '') : output
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user