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