mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 01:01:11 +03:00
add llamaindex
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
||||
import { ResponseSynthesizerClass } from '../base'
|
||||
|
||||
class CompactRefine_LlamaIndex implements INode {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
description: string
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
tags: string[]
|
||||
inputs: INodeParams[]
|
||||
outputs: INodeOutputsValue[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Compact and Refine'
|
||||
this.name = 'compactrefineLlamaIndex'
|
||||
this.version = 1.0
|
||||
this.type = 'CompactRefine'
|
||||
this.icon = 'compactrefine.svg'
|
||||
this.category = 'Response Synthesizer'
|
||||
this.description =
|
||||
'CompactRefine is a slight variation of Refine that first compacts the text chunks into the smallest possible number of chunks.'
|
||||
this.baseClasses = [this.type, 'ResponseSynthesizer']
|
||||
this.tags = ['LlamaIndex']
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Refine Prompt',
|
||||
name: 'refinePrompt',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
default: `The original query is as follows: {query}
|
||||
We have provided an existing answer: {existingAnswer}
|
||||
We have the opportunity to refine the existing answer (only if needed) with some more context below.
|
||||
------------
|
||||
{context}
|
||||
------------
|
||||
Given the new context, refine the original answer to better answer the query. If the context isn't useful, return the original answer.
|
||||
Refined Answer:`,
|
||||
warning: `Prompt can contains no variables, or up to 3 variables. Variables must be {existingAnswer}, {context} and {query}`,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Text QA Prompt',
|
||||
name: 'textQAPrompt',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
default: `Context information is below.
|
||||
---------------------
|
||||
{context}
|
||||
---------------------
|
||||
Given the context information and not prior knowledge, answer the query.
|
||||
Query: {query}
|
||||
Answer:`,
|
||||
warning: `Prompt can contains no variables, or up to 2 variables. Variables must be {context} and {query}`,
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const refinePrompt = nodeData.inputs?.refinePrompt as string
|
||||
const textQAPrompt = nodeData.inputs?.textQAPrompt as string
|
||||
|
||||
const refinePromptTemplate = ({ context = '', existingAnswer = '', query = '' }) =>
|
||||
refinePrompt.replace('{existingAnswer}', existingAnswer).replace('{context}', context).replace('{query}', query)
|
||||
const textQAPromptTemplate = ({ context = '', query = '' }) => textQAPrompt.replace('{context}', context).replace('{query}', query)
|
||||
|
||||
return new ResponseSynthesizerClass({ textQAPromptTemplate, refinePromptTemplate, type: 'CompactAndRefine' })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: CompactRefine_LlamaIndex }
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-layers-difference" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M16 16v2a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-8a2 2 0 0 1 2 -2h2v-2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-2" /><path d="M10 8l-2 0l0 2" /><path d="M8 14l0 2l2 0" /><path d="M14 8l2 0l0 2" /><path d="M16 14l0 2l-2 0" /></svg>
|
||||
|
After Width: | Height: | Size: 529 B |
@@ -0,0 +1,75 @@
|
||||
import { INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
||||
import { ResponseSynthesizerClass } from '../base'
|
||||
|
||||
class Refine_LlamaIndex implements INode {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
description: string
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
tags: string[]
|
||||
inputs: INodeParams[]
|
||||
outputs: INodeOutputsValue[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Refine'
|
||||
this.name = 'refineLlamaIndex'
|
||||
this.version = 1.0
|
||||
this.type = 'Refine'
|
||||
this.icon = 'refine.svg'
|
||||
this.category = 'Response Synthesizer'
|
||||
this.description =
|
||||
'Create and refine an answer by sequentially going through each retrieved text chunk. This makes a separate LLM call per Node. Good for more detailed answers.'
|
||||
this.baseClasses = [this.type, 'ResponseSynthesizer']
|
||||
this.tags = ['LlamaIndex']
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Refine Prompt',
|
||||
name: 'refinePrompt',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
default: `The original query is as follows: {query}
|
||||
We have provided an existing answer: {existingAnswer}
|
||||
We have the opportunity to refine the existing answer (only if needed) with some more context below.
|
||||
------------
|
||||
{context}
|
||||
------------
|
||||
Given the new context, refine the original answer to better answer the query. If the context isn't useful, return the original answer.
|
||||
Refined Answer:`,
|
||||
warning: `Prompt can contains no variables, or up to 3 variables. Variables must be {existingAnswer}, {context} and {query}`,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Text QA Prompt',
|
||||
name: 'textQAPrompt',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
default: `Context information is below.
|
||||
---------------------
|
||||
{context}
|
||||
---------------------
|
||||
Given the context information and not prior knowledge, answer the query.
|
||||
Query: {query}
|
||||
Answer:`,
|
||||
warning: `Prompt can contains no variables, or up to 2 variables. Variables must be {context} and {query}`,
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const refinePrompt = nodeData.inputs?.refinePrompt as string
|
||||
const textQAPrompt = nodeData.inputs?.textQAPrompt as string
|
||||
|
||||
const refinePromptTemplate = ({ context = '', existingAnswer = '', query = '' }) =>
|
||||
refinePrompt.replace('{existingAnswer}', existingAnswer).replace('{context}', context).replace('{query}', query)
|
||||
const textQAPromptTemplate = ({ context = '', query = '' }) => textQAPrompt.replace('{context}', context).replace('{query}', query)
|
||||
|
||||
return new ResponseSynthesizerClass({ textQAPromptTemplate, refinePromptTemplate, type: 'Refine' })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: Refine_LlamaIndex }
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-filter-search" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M11.36 20.213l-2.36 .787v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227h16v2.172a2 2 0 0 1 -.586 1.414l-4.414 4.414" /><path d="M18 18m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0" /><path d="M20.2 20.2l1.8 1.8" /></svg>
|
||||
|
After Width: | Height: | Size: 501 B |
+35
@@ -0,0 +1,35 @@
|
||||
import { INode, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
||||
import { ResponseSynthesizerClass } from '../base'
|
||||
|
||||
class SimpleResponseBuilder_LlamaIndex implements INode {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
description: string
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
tags: string[]
|
||||
inputs: INodeParams[]
|
||||
outputs: INodeOutputsValue[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Simple Response Builder'
|
||||
this.name = 'simpleResponseBuilderLlamaIndex'
|
||||
this.version = 1.0
|
||||
this.type = 'SimpleResponseBuilder'
|
||||
this.icon = 'simplerb.svg'
|
||||
this.category = 'Response Synthesizer'
|
||||
this.description = `Apply a query to a collection of text chunks, gathering the responses in an array, and return a combined string of all responses. Useful for individual queries on each text chunk.`
|
||||
this.baseClasses = [this.type, 'ResponseSynthesizer']
|
||||
this.tags = ['LlamaIndex']
|
||||
this.inputs = []
|
||||
}
|
||||
|
||||
async init(): Promise<any> {
|
||||
return new ResponseSynthesizerClass({ type: 'SimpleResponseBuilder' })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: SimpleResponseBuilder_LlamaIndex }
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-quote" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M10 11h-4a1 1 0 0 1 -1 -1v-3a1 1 0 0 1 1 -1h3a1 1 0 0 1 1 1v6c0 2.667 -1.333 4.333 -4 5" /><path d="M19 11h-4a1 1 0 0 1 -1 -1v-3a1 1 0 0 1 1 -1h3a1 1 0 0 1 1 1v6c0 2.667 -1.333 4.333 -4 5" /></svg>
|
||||
|
After Width: | Height: | Size: 481 B |
@@ -0,0 +1,56 @@
|
||||
import { INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
||||
import { ResponseSynthesizerClass } from '../base'
|
||||
|
||||
class TreeSummarize_LlamaIndex implements INode {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
description: string
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
tags: string[]
|
||||
inputs: INodeParams[]
|
||||
outputs: INodeOutputsValue[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'TreeSummarize'
|
||||
this.name = 'treeSummarizeLlamaIndex'
|
||||
this.version = 1.0
|
||||
this.type = 'TreeSummarize'
|
||||
this.icon = 'treesummarize.svg'
|
||||
this.category = 'Response Synthesizer'
|
||||
this.description =
|
||||
'Given a set of text chunks and the query, recursively construct a tree and return the root node as the response. Good for summarization purposes.'
|
||||
this.baseClasses = [this.type, 'ResponseSynthesizer']
|
||||
this.tags = ['LlamaIndex']
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Prompt',
|
||||
name: 'prompt',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
default: `Context information from multiple sources is below.
|
||||
---------------------
|
||||
{context}
|
||||
---------------------
|
||||
Given the information from multiple sources and not prior knowledge, answer the query.
|
||||
Query: {query}
|
||||
Answer:`,
|
||||
warning: `Prompt can contains no variables, or up to 2 variables. Variables must be {context} and {query}`,
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const prompt = nodeData.inputs?.prompt as string
|
||||
|
||||
const textQAPromptTemplate = ({ context = '', query = '' }) => prompt.replace('{context}', context).replace('{query}', query)
|
||||
|
||||
return new ResponseSynthesizerClass({ textQAPromptTemplate, type: 'TreeSummarize' })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: TreeSummarize_LlamaIndex }
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-tree" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 13l-2 -2" /><path d="M12 12l2 -2" /><path d="M12 21v-13" /><path d="M9.824 16a3 3 0 0 1 -2.743 -3.69a3 3 0 0 1 .304 -4.833a3 3 0 0 1 4.615 -3.707a3 3 0 0 1 4.614 3.707a3 3 0 0 1 .305 4.833a3 3 0 0 1 -2.919 3.695h-4z" /></svg>
|
||||
|
After Width: | Height: | Size: 512 B |
@@ -0,0 +1,11 @@
|
||||
export class ResponseSynthesizerClass {
|
||||
type: string
|
||||
textQAPromptTemplate?: any
|
||||
refinePromptTemplate?: any
|
||||
|
||||
constructor(params: { type: string; textQAPromptTemplate?: any; refinePromptTemplate?: any }) {
|
||||
this.type = params.type
|
||||
this.textQAPromptTemplate = params.textQAPromptTemplate
|
||||
this.refinePromptTemplate = params.refinePromptTemplate
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user