mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
fix output prediction output parser
This commit is contained in:
@@ -82,7 +82,7 @@ class LLMChain_Chains implements INode {
|
|||||||
const model = nodeData.inputs?.model as BaseLanguageModel
|
const model = nodeData.inputs?.model as BaseLanguageModel
|
||||||
const prompt = nodeData.inputs?.prompt
|
const prompt = nodeData.inputs?.prompt
|
||||||
const output = nodeData.outputs?.output as string
|
const output = nodeData.outputs?.output as string
|
||||||
const promptValues = prompt.promptValues as ICommonObject
|
let promptValues: ICommonObject | undefined = nodeData.inputs?.prompt.promptValues as ICommonObject
|
||||||
const llmOutputParser = nodeData.inputs?.outputParser as BaseOutputParser
|
const llmOutputParser = nodeData.inputs?.outputParser as BaseOutputParser
|
||||||
this.outputParser = llmOutputParser
|
this.outputParser = llmOutputParser
|
||||||
if (llmOutputParser) {
|
if (llmOutputParser) {
|
||||||
@@ -107,17 +107,24 @@ class LLMChain_Chains implements INode {
|
|||||||
verbose: process.env.DEBUG === 'true'
|
verbose: process.env.DEBUG === 'true'
|
||||||
})
|
})
|
||||||
const inputVariables = chain.prompt.inputVariables as string[] // ["product"]
|
const inputVariables = chain.prompt.inputVariables as string[] // ["product"]
|
||||||
|
promptValues = injectOutputParser(this.outputParser, chain, promptValues)
|
||||||
const res = await runPrediction(inputVariables, chain, input, promptValues, options, nodeData)
|
const res = await runPrediction(inputVariables, chain, input, promptValues, options, nodeData)
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('\x1b[92m\x1b[1m\n*****OUTPUT PREDICTION*****\n\x1b[0m\x1b[0m')
|
console.log('\x1b[92m\x1b[1m\n*****OUTPUT PREDICTION*****\n\x1b[0m\x1b[0m')
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(res)
|
console.log(res)
|
||||||
|
|
||||||
|
let finalRes = res
|
||||||
|
if (this.outputParser && typeof res === 'object' && Object.prototype.hasOwnProperty.call(res, 'json')) {
|
||||||
|
finalRes = (res as ICommonObject).json
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply string transformation to convert special chars:
|
* Apply string transformation to convert special chars:
|
||||||
* FROM: hello i am ben\n\n\thow are you?
|
* FROM: hello i am ben\n\n\thow are you?
|
||||||
* TO: hello i am benFLOWISE_NEWLINEFLOWISE_NEWLINEFLOWISE_TABhow are you?
|
* TO: hello i am benFLOWISE_NEWLINEFLOWISE_NEWLINEFLOWISE_TABhow are you?
|
||||||
*/
|
*/
|
||||||
return handleEscapeCharacters(res, false)
|
return handleEscapeCharacters(finalRes, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,17 @@ class CustomFunction_Utilities implements INode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some values might be a stringified JSON, parse it
|
||||||
|
for (const key in inputVars) {
|
||||||
|
if (typeof inputVars[key] === 'string' && inputVars[key].startsWith('{') && inputVars[key].endsWith('}')) {
|
||||||
|
try {
|
||||||
|
inputVars[key] = JSON.parse(inputVars[key])
|
||||||
|
} catch (e) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let sandbox: any = { $input: input }
|
let sandbox: any = { $input: input }
|
||||||
sandbox['$vars'] = prepareSandboxVars(variables)
|
sandbox['$vars'] = prepareSandboxVars(variables)
|
||||||
sandbox['$flow'] = flow
|
sandbox['$flow'] = flow
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ICommonObject, IDatabaseEntity, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
import { ICommonObject, IDatabaseEntity, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
||||||
import { NodeVM } from 'vm2'
|
import { NodeVM } from 'vm2'
|
||||||
import { DataSource } from 'typeorm'
|
import { DataSource } from 'typeorm'
|
||||||
import { availableDependencies, defaultAllowBuiltInDep, getVars, prepareSandboxVars } from '../../../src/utils'
|
import { availableDependencies, defaultAllowBuiltInDep, getVars, handleEscapeCharacters, prepareSandboxVars } from '../../../src/utils'
|
||||||
|
|
||||||
class IfElseFunction_Utilities implements INode {
|
class IfElseFunction_Utilities implements INode {
|
||||||
label: string
|
label: string
|
||||||
@@ -95,7 +95,18 @@ class IfElseFunction_Utilities implements INode {
|
|||||||
inputVars =
|
inputVars =
|
||||||
typeof functionInputVariablesRaw === 'object' ? functionInputVariablesRaw : JSON.parse(functionInputVariablesRaw)
|
typeof functionInputVariablesRaw === 'object' ? functionInputVariablesRaw : JSON.parse(functionInputVariablesRaw)
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
throw new Error("Invalid JSON in the PromptTemplate's promptValues: " + exception)
|
throw new Error("Invalid JSON in the IfElse's Input Variables: " + exception)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some values might be a stringified JSON, parse it
|
||||||
|
for (const key in inputVars) {
|
||||||
|
if (typeof inputVars[key] === 'string' && inputVars[key].startsWith('{') && inputVars[key].endsWith('}')) {
|
||||||
|
try {
|
||||||
|
inputVars[key] = JSON.parse(inputVars[key])
|
||||||
|
} catch (e) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +116,11 @@ class IfElseFunction_Utilities implements INode {
|
|||||||
|
|
||||||
if (Object.keys(inputVars).length) {
|
if (Object.keys(inputVars).length) {
|
||||||
for (const item in inputVars) {
|
for (const item in inputVars) {
|
||||||
sandbox[`$${item}`] = inputVars[item]
|
let value = inputVars[item]
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
value = handleEscapeCharacters(value, true)
|
||||||
|
}
|
||||||
|
sandbox[`$${item}`] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user