mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Add sentence config to Flowise
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
||||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
import { VectaraStore, VectaraLibArgs, VectaraFilter } from 'langchain/vectorstores/vectara'
|
import { VectaraStore, VectaraLibArgs, VectaraFilter, VectaraContextConfig } from 'langchain/vectorstores/vectara'
|
||||||
|
|
||||||
class VectaraExisting_VectorStores implements INode {
|
class VectaraExisting_VectorStores implements INode {
|
||||||
label: string
|
label: string
|
||||||
@@ -40,6 +40,20 @@ class VectaraExisting_VectorStores implements INode {
|
|||||||
additionalParams: true,
|
additionalParams: true,
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Sentences Before',
|
||||||
|
name: 'sentencesBefore',
|
||||||
|
type: 'number',
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Sentences After',
|
||||||
|
name: 'sentencesAfter',
|
||||||
|
type: 'number',
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Lambda',
|
label: 'Lambda',
|
||||||
name: 'lambda',
|
name: 'lambda',
|
||||||
@@ -77,6 +91,8 @@ class VectaraExisting_VectorStores implements INode {
|
|||||||
const corpusId = getCredentialParam('corpusID', credentialData, nodeData)
|
const corpusId = getCredentialParam('corpusID', credentialData, nodeData)
|
||||||
|
|
||||||
const vectaraMetadataFilter = nodeData.inputs?.filter as string
|
const vectaraMetadataFilter = nodeData.inputs?.filter as string
|
||||||
|
const sentencesBefore = nodeData.inputs?.sentencesBefore as number
|
||||||
|
const sentencesAfter = nodeData.inputs?.sentencesAfter as number
|
||||||
const lambda = nodeData.inputs?.lambda as number
|
const lambda = nodeData.inputs?.lambda as number
|
||||||
const output = nodeData.outputs?.output as string
|
const output = nodeData.outputs?.output as string
|
||||||
const topK = nodeData.inputs?.topK as string
|
const topK = nodeData.inputs?.topK as string
|
||||||
@@ -92,6 +108,11 @@ class VectaraExisting_VectorStores implements INode {
|
|||||||
if (vectaraMetadataFilter) vectaraFilter.filter = vectaraMetadataFilter
|
if (vectaraMetadataFilter) vectaraFilter.filter = vectaraMetadataFilter
|
||||||
if (lambda) vectaraFilter.lambda = lambda
|
if (lambda) vectaraFilter.lambda = lambda
|
||||||
|
|
||||||
|
const vectaraContextConfig: VectaraContextConfig = {}
|
||||||
|
if (sentencesBefore) vectaraContextConfig.sentencesBefore = sentencesBefore
|
||||||
|
if (sentencesAfter) vectaraContextConfig.sentencesAfter = sentencesAfter
|
||||||
|
vectaraFilter.contextConfig = vectaraContextConfig
|
||||||
|
|
||||||
const vectorStore = new VectaraStore(vectaraArgs)
|
const vectorStore = new VectaraStore(vectaraArgs)
|
||||||
|
|
||||||
if (output === 'retriever') {
|
if (output === 'retriever') {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
||||||
import { Embeddings } from 'langchain/embeddings/base'
|
import { Embeddings } from 'langchain/embeddings/base'
|
||||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
import { VectaraStore, VectaraLibArgs, VectaraFilter } from 'langchain/vectorstores/vectara'
|
import { VectaraStore, VectaraLibArgs, VectaraFilter, VectaraContextConfig } from 'langchain/vectorstores/vectara'
|
||||||
import { Document } from 'langchain/document'
|
import { Document } from 'langchain/document'
|
||||||
import { flatten } from 'lodash'
|
import { flatten } from 'lodash'
|
||||||
|
|
||||||
@@ -49,6 +49,20 @@ class VectaraUpsert_VectorStores implements INode {
|
|||||||
additionalParams: true,
|
additionalParams: true,
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Sentences Before',
|
||||||
|
name: 'sentencesBefore',
|
||||||
|
type: 'number',
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Sentences After',
|
||||||
|
name: 'sentencesAfter',
|
||||||
|
type: 'number',
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Lambda',
|
label: 'Lambda',
|
||||||
name: 'lambda',
|
name: 'lambda',
|
||||||
@@ -88,6 +102,8 @@ class VectaraUpsert_VectorStores implements INode {
|
|||||||
const docs = nodeData.inputs?.document as Document[]
|
const docs = nodeData.inputs?.document as Document[]
|
||||||
const embeddings = {} as Embeddings
|
const embeddings = {} as Embeddings
|
||||||
const vectaraMetadataFilter = nodeData.inputs?.filter as string
|
const vectaraMetadataFilter = nodeData.inputs?.filter as string
|
||||||
|
const sentencesBefore = nodeData.inputs?.sentencesBefore as number
|
||||||
|
const sentencesAfter = nodeData.inputs?.sentencesAfter as number
|
||||||
const lambda = nodeData.inputs?.lambda as number
|
const lambda = nodeData.inputs?.lambda as number
|
||||||
const output = nodeData.outputs?.output as string
|
const output = nodeData.outputs?.output as string
|
||||||
const topK = nodeData.inputs?.topK as string
|
const topK = nodeData.inputs?.topK as string
|
||||||
@@ -103,6 +119,11 @@ class VectaraUpsert_VectorStores implements INode {
|
|||||||
if (vectaraMetadataFilter) vectaraFilter.filter = vectaraMetadataFilter
|
if (vectaraMetadataFilter) vectaraFilter.filter = vectaraMetadataFilter
|
||||||
if (lambda) vectaraFilter.lambda = lambda
|
if (lambda) vectaraFilter.lambda = lambda
|
||||||
|
|
||||||
|
const vectaraContextConfig: VectaraContextConfig = {}
|
||||||
|
if (sentencesBefore) vectaraContextConfig.sentencesBefore = sentencesBefore
|
||||||
|
if (sentencesAfter) vectaraContextConfig.sentencesAfter = sentencesAfter
|
||||||
|
vectaraFilter.contextConfig = vectaraContextConfig
|
||||||
|
|
||||||
const flattenDocs = docs && docs.length ? flatten(docs) : []
|
const flattenDocs = docs && docs.length ? flatten(docs) : []
|
||||||
const finalDocs = []
|
const finalDocs = []
|
||||||
for (let i = 0; i < flattenDocs.length; i += 1) {
|
for (let i = 0; i < flattenDocs.length; i += 1) {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
"google-auth-library": "^9.0.0",
|
"google-auth-library": "^9.0.0",
|
||||||
"graphql": "^16.6.0",
|
"graphql": "^16.6.0",
|
||||||
"html-to-text": "^9.0.5",
|
"html-to-text": "^9.0.5",
|
||||||
"langchain": "^0.0.122",
|
"langchain": "^0.0.126",
|
||||||
"linkifyjs": "^4.1.1",
|
"linkifyjs": "^4.1.1",
|
||||||
"mammoth": "^1.5.1",
|
"mammoth": "^1.5.1",
|
||||||
"moment": "^2.29.3",
|
"moment": "^2.29.3",
|
||||||
|
|||||||
Reference in New Issue
Block a user