mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Merge pull request #440 from FlowiseAI/feature/FormatPromptValues
Feature/FormatPromptValues Revamp
This commit is contained in:
@@ -50,7 +50,7 @@ class LLMChain_Chains implements INode {
|
||||
{
|
||||
label: 'Output Prediction',
|
||||
name: 'outputPrediction',
|
||||
baseClasses: ['string']
|
||||
baseClasses: ['string', 'json']
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -38,12 +38,7 @@ class ChatPromptTemplate_Prompts implements INode {
|
||||
{
|
||||
label: 'Format Prompt Values',
|
||||
name: 'promptValues',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
placeholder: `{
|
||||
"input_language": "English",
|
||||
"output_language": "French"
|
||||
}`,
|
||||
type: 'json',
|
||||
optional: true,
|
||||
acceptVariable: true,
|
||||
list: true
|
||||
|
||||
@@ -31,12 +31,7 @@ class PromptTemplate_Prompts implements INode {
|
||||
{
|
||||
label: 'Format Prompt Values',
|
||||
name: 'promptValues',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
placeholder: `{
|
||||
"input_language": "English",
|
||||
"output_language": "French"
|
||||
}`,
|
||||
type: 'json',
|
||||
optional: true,
|
||||
acceptVariable: true,
|
||||
list: true
|
||||
|
||||
@@ -245,47 +245,6 @@ export class CustomChainHandler extends BaseCallbackHandler {
|
||||
}
|
||||
}
|
||||
|
||||
export const returnJSONStr = (jsonStr: string): string => {
|
||||
let jsonStrArray = jsonStr.split(':')
|
||||
|
||||
let wholeString = ''
|
||||
for (let i = 0; i < jsonStrArray.length; i++) {
|
||||
if (jsonStrArray[i].includes(',') && jsonStrArray[i + 1] !== undefined) {
|
||||
const splitValueAndTitle = jsonStrArray[i].split(',')
|
||||
const value = splitValueAndTitle[0]
|
||||
const newTitle = splitValueAndTitle[1]
|
||||
wholeString += handleEscapeDoubleQuote(value) + ',' + newTitle + ':'
|
||||
} else {
|
||||
wholeString += wholeString === '' ? jsonStrArray[i] + ':' : handleEscapeDoubleQuote(jsonStrArray[i])
|
||||
}
|
||||
}
|
||||
return wholeString
|
||||
}
|
||||
|
||||
const handleEscapeDoubleQuote = (value: string): string => {
|
||||
let newValue = ''
|
||||
if (value.includes('"')) {
|
||||
const valueArray = value.split('"')
|
||||
for (let i = 0; i < valueArray.length; i++) {
|
||||
if ((i + 1) % 2 !== 0) {
|
||||
switch (valueArray[i]) {
|
||||
case '':
|
||||
newValue += '"'
|
||||
break
|
||||
case '}':
|
||||
newValue += '"}'
|
||||
break
|
||||
default:
|
||||
newValue += '\\"' + valueArray[i] + '\\"'
|
||||
}
|
||||
} else {
|
||||
newValue += valueArray[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
return newValue === '' ? value : newValue
|
||||
}
|
||||
|
||||
export const availableDependencies = [
|
||||
'@dqbd/tiktoken',
|
||||
'@getzep/zep-js',
|
||||
|
||||
Reference in New Issue
Block a user