Merge branch 'FlowiseAI:main' into sentence-config

This commit is contained in:
Seif
2023-08-16 09:50:35 -07:00
committed by GitHub
3 changed files with 88 additions and 33 deletions
@@ -5,6 +5,9 @@ import { DataSource } from 'typeorm'
import { SqlDatabase } from 'langchain/sql_db' import { SqlDatabase } from 'langchain/sql_db'
import { BaseLanguageModel } from 'langchain/base_language' import { BaseLanguageModel } from 'langchain/base_language'
import { ConsoleCallbackHandler, CustomChainHandler } from '../../../src/handler' import { ConsoleCallbackHandler, CustomChainHandler } from '../../../src/handler'
import { DataSourceOptions } from 'typeorm/data-source'
type DatabaseType = 'sqlite' | 'postgres' | 'mssql' | 'mysql'
class SqlDatabaseChain_Chains implements INode { class SqlDatabaseChain_Chains implements INode {
label: string label: string
@@ -38,36 +41,48 @@ class SqlDatabaseChain_Chains implements INode {
type: 'options', type: 'options',
options: [ options: [
{ {
label: 'SQlite', label: 'SQLite',
name: 'sqlite' name: 'sqlite'
},
{
label: 'PostgreSQL',
name: 'postgres'
},
{
label: 'MSSQL',
name: 'mssql'
},
{
label: 'MySQL',
name: 'mysql'
} }
], ],
default: 'sqlite' default: 'sqlite'
}, },
{ {
label: 'Database File Path', label: 'Connection string or file path (sqlite only)',
name: 'dbFilePath', name: 'url',
type: 'string', type: 'string',
placeholder: 'C:/Users/chinook.db' placeholder: '1270.0.0.1:5432/chinook'
} }
] ]
} }
async init(nodeData: INodeData): Promise<any> { async init(nodeData: INodeData): Promise<any> {
const databaseType = nodeData.inputs?.database as 'sqlite' const databaseType = nodeData.inputs?.database as DatabaseType
const model = nodeData.inputs?.model as BaseLanguageModel const model = nodeData.inputs?.model as BaseLanguageModel
const dbFilePath = nodeData.inputs?.dbFilePath const url = nodeData.inputs?.url
const chain = await getSQLDBChain(databaseType, dbFilePath, model) const chain = await getSQLDBChain(databaseType, url, model)
return chain return chain
} }
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> { async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
const databaseType = nodeData.inputs?.database as 'sqlite' const databaseType = nodeData.inputs?.database as DatabaseType
const model = nodeData.inputs?.model as BaseLanguageModel const model = nodeData.inputs?.model as BaseLanguageModel
const dbFilePath = nodeData.inputs?.dbFilePath const url = nodeData.inputs?.url
const chain = await getSQLDBChain(databaseType, dbFilePath, model) const chain = await getSQLDBChain(databaseType, url, model)
const loggerHandler = new ConsoleCallbackHandler(options.logger) const loggerHandler = new ConsoleCallbackHandler(options.logger)
if (options.socketIO && options.socketIOClientId) { if (options.socketIO && options.socketIOClientId) {
@@ -81,11 +96,18 @@ class SqlDatabaseChain_Chains implements INode {
} }
} }
const getSQLDBChain = async (databaseType: 'sqlite', dbFilePath: string, llm: BaseLanguageModel) => { const getSQLDBChain = async (databaseType: DatabaseType, url: string, llm: BaseLanguageModel) => {
const datasource = new DataSource({ const datasource = new DataSource(
databaseType === 'sqlite'
? {
type: databaseType, type: databaseType,
database: dbFilePath database: url
}) }
: ({
type: databaseType,
url: url
} as DataSourceOptions)
)
const db = await SqlDatabase.fromDataSourceParams({ const db = await SqlDatabase.fromDataSourceParams({
appDataSource: datasource appDataSource: datasource
@@ -61,7 +61,40 @@ class Folder_DocumentLoaders implements INode {
'.csv': (path) => new CSVLoader(path), '.csv': (path) => new CSVLoader(path),
'.docx': (path) => new DocxLoader(path), '.docx': (path) => new DocxLoader(path),
// @ts-ignore // @ts-ignore
'.pdf': (path) => new PDFLoader(path, { pdfjs: () => import('pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js') }) '.pdf': (path) => new PDFLoader(path, { pdfjs: () => import('pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js') }),
'.aspx': (path) => new TextLoader(path),
'.asp': (path) => new TextLoader(path),
'.cpp': (path) => new TextLoader(path), // C++
'.c': (path) => new TextLoader(path),
'.cs': (path) => new TextLoader(path),
'.css': (path) => new TextLoader(path),
'.go': (path) => new TextLoader(path), // Go
'.h': (path) => new TextLoader(path), // C++ Header files
'.java': (path) => new TextLoader(path), // Java
'.js': (path) => new TextLoader(path), // JavaScript
'.less': (path) => new TextLoader(path), // Less files
'.ts': (path) => new TextLoader(path), // TypeScript
'.php': (path) => new TextLoader(path), // PHP
'.proto': (path) => new TextLoader(path), // Protocol Buffers
'.python': (path) => new TextLoader(path), // Python
'.py': (path) => new TextLoader(path), // Python
'.rst': (path) => new TextLoader(path), // reStructuredText
'.ruby': (path) => new TextLoader(path), // Ruby
'.rb': (path) => new TextLoader(path), // Ruby
'.rs': (path) => new TextLoader(path), // Rust
'.scala': (path) => new TextLoader(path), // Scala
'.sc': (path) => new TextLoader(path), // Scala
'.scss': (path) => new TextLoader(path), // Sass
'.sol': (path) => new TextLoader(path), // Solidity
'.sql': (path) => new TextLoader(path), //SQL
'.swift': (path) => new TextLoader(path), // Swift
'.markdown': (path) => new TextLoader(path), // Markdown
'.md': (path) => new TextLoader(path), // Markdown
'.tex': (path) => new TextLoader(path), // LaTeX
'.ltx': (path) => new TextLoader(path), // LaTeX
'.html': (path) => new TextLoader(path), // HTML
'.vb': (path) => new TextLoader(path), // Visual Basic
'.xml': (path) => new TextLoader(path) // XML
}) })
let docs = [] let docs = []
@@ -4,14 +4,14 @@
{ {
"width": 300, "width": 300,
"height": 408, "height": 408,
"id": "vectaraExisting_0", "id": "vectaraUpsert_0",
"position": { "x": 438, "y": 214 }, "position": { "x": 438, "y": 214 },
"type": "customNode", "type": "customNode",
"data": { "data": {
"id": "vectaraExisting_0", "id": "vectaraUpsert_0",
"label": "Vectara Upsert Document", "label": "Vectara Upsert Document",
"version": 1, "version": 1,
"name": "vectaraExisting", "name": "vectaraUpsert",
"type": "Vectara", "type": "Vectara",
"baseClasses": ["Vectara", "VectorStoreRetriever", "BaseRetriever"], "baseClasses": ["Vectara", "VectorStoreRetriever", "BaseRetriever"],
"category": "Vector Stores", "category": "Vector Stores",
@@ -22,7 +22,7 @@
"name": "credential", "name": "credential",
"type": "credential", "type": "credential",
"credentialNames": ["vectaraApi"], "credentialNames": ["vectaraApi"],
"id": "vectaraExisting_0-input-credential-credential" "id": "vectaraUpsert_0-input-credential-credential"
}, },
{ {
"label": "Filter", "label": "Filter",
@@ -30,7 +30,7 @@
"type": "json", "type": "json",
"additionalParams": true, "additionalParams": true,
"optional": true, "optional": true,
"id": "vectaraExisting_0-input-filter-json" "id": "vectaraUpsert_0-input-filter-json"
}, },
{ {
"label": "Lambda", "label": "Lambda",
@@ -38,7 +38,7 @@
"type": "number", "type": "number",
"additionalParams": true, "additionalParams": true,
"optional": true, "optional": true,
"id": "vectaraExisting_0-input-lambda-number" "id": "vectaraUpsert_0-input-lambda-number"
}, },
{ {
"label": "Top K", "label": "Top K",
@@ -48,7 +48,7 @@
"type": "number", "type": "number",
"additionalParams": true, "additionalParams": true,
"optional": true, "optional": true,
"id": "vectaraExisting_0-input-topK-number" "id": "vectaraUpsert_0-input-topK-number"
} }
], ],
"inputAnchors": [ "inputAnchors": [
@@ -57,7 +57,7 @@
"name": "document", "name": "document",
"type": "Document", "type": "Document",
"list": true, "list": true,
"id": "vectaraExisting_0-input-document-Document" "id": "vectaraUpsert_0-input-document-Document"
} }
], ],
"inputs": { "inputs": {
@@ -73,13 +73,13 @@
"type": "options", "type": "options",
"options": [ "options": [
{ {
"id": "vectaraExisting_0-output-retriever-Vectara|VectorStoreRetriever|BaseRetriever", "id": "vectaraUpsert_0-output-retriever-Vectara|VectorStoreRetriever|BaseRetriever",
"name": "retriever", "name": "retriever",
"label": "Vectara Retriever", "label": "Vectara Retriever",
"type": "Vectara | VectorStoreRetriever | BaseRetriever" "type": "Vectara | VectorStoreRetriever | BaseRetriever"
}, },
{ {
"id": "vectaraExisting_0-output-vectorStore-Vectara|VectorStore", "id": "vectaraUpsert_0-output-vectorStore-Vectara|VectorStore",
"name": "vectorStore", "name": "vectorStore",
"label": "Vectara Vector Store", "label": "Vectara Vector Store",
"type": "Vectara | VectorStore" "type": "Vectara | VectorStore"
@@ -392,7 +392,7 @@
], ],
"inputs": { "inputs": {
"model": "{{chatOpenAI_0.data.instance}}", "model": "{{chatOpenAI_0.data.instance}}",
"vectorStoreRetriever": "{{vectaraExisting_0.data.instance}}", "vectorStoreRetriever": "{{vectaraUpsert_0.data.instance}}",
"memory": "", "memory": "",
"returnSourceDocuments": "", "returnSourceDocuments": "",
"systemMessagePrompt": "", "systemMessagePrompt": "",
@@ -418,19 +418,19 @@
{ {
"source": "pdfFile_0", "source": "pdfFile_0",
"sourceHandle": "pdfFile_0-output-pdfFile-Document", "sourceHandle": "pdfFile_0-output-pdfFile-Document",
"target": "vectaraExisting_0", "target": "vectaraUpsert_0",
"targetHandle": "vectaraExisting_0-input-document-Document", "targetHandle": "vectaraUpsert_0-input-document-Document",
"type": "buttonedge", "type": "buttonedge",
"id": "pdfFile_0-pdfFile_0-output-pdfFile-Document-vectaraExisting_0-vectaraExisting_0-input-document-Document", "id": "pdfFile_0-pdfFile_0-output-pdfFile-Document-vectaraUpsert_0-vectaraUpsert_0-input-document-Document",
"data": { "label": "" } "data": { "label": "" }
}, },
{ {
"source": "vectaraExisting_0", "source": "vectaraUpsert_0",
"sourceHandle": "vectaraExisting_0-output-retriever-Vectara|VectorStoreRetriever|BaseRetriever", "sourceHandle": "vectaraUpsert_0-output-retriever-Vectara|VectorStoreRetriever|BaseRetriever",
"target": "conversationalRetrievalQAChain_0", "target": "conversationalRetrievalQAChain_0",
"targetHandle": "conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever", "targetHandle": "conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever",
"type": "buttonedge", "type": "buttonedge",
"id": "vectaraExisting_0-vectaraExisting_0-output-retriever-Vectara|VectorStoreRetriever|BaseRetriever-conversationalRetrievalQAChain_0-conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever", "id": "vectaraUpsert_0-vectaraUpsert_0-output-retriever-Vectara|VectorStoreRetriever|BaseRetriever-conversationalRetrievalQAChain_0-conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever",
"data": { "label": "" } "data": { "label": "" }
}, },
{ {