mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 15:00:57 +03:00
Merge pull request #22 from FlowiseAI/feature/SQLDatabaseChain
Feature/SQLDatabaseChain
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { SqlDatabaseChain } from 'langchain/chains'
|
||||
import { getBaseClasses } from '../../../src/utils'
|
||||
import { DataSource } from 'typeorm'
|
||||
import { SqlDatabase } from 'langchain/sql_db'
|
||||
import { BaseLLM } from 'langchain/llms/base'
|
||||
|
||||
class SqlDatabaseChain_Chains implements INode {
|
||||
label: string
|
||||
name: string
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
description: string
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Sql Database Chain'
|
||||
this.name = 'sqlDatabaseChain'
|
||||
this.type = 'SqlDatabaseChain'
|
||||
this.icon = 'sqlchain.svg'
|
||||
this.category = 'Chains'
|
||||
this.description = 'Answer questions over a SQL database'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(SqlDatabaseChain)]
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'LLM',
|
||||
name: 'llm',
|
||||
type: 'BaseLLM'
|
||||
},
|
||||
{
|
||||
label: 'Database',
|
||||
name: 'database',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
label: 'SQlite',
|
||||
name: 'sqlite'
|
||||
}
|
||||
],
|
||||
default: 'sqlite'
|
||||
},
|
||||
{
|
||||
label: 'Database File Path',
|
||||
name: 'dbFilePath',
|
||||
type: 'string',
|
||||
placeholder: 'C:/Users/chinook.db'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const databaseType = nodeData.inputs?.database
|
||||
const llm = nodeData.inputs?.llm as BaseLLM
|
||||
const dbFilePath = nodeData.inputs?.dbFilePath
|
||||
|
||||
const datasource = new DataSource({
|
||||
type: databaseType,
|
||||
database: dbFilePath
|
||||
})
|
||||
|
||||
const db = await SqlDatabase.fromDataSourceParams({
|
||||
appDataSource: datasource
|
||||
})
|
||||
|
||||
const chain = new SqlDatabaseChain({
|
||||
llm,
|
||||
database: db
|
||||
})
|
||||
return chain
|
||||
}
|
||||
|
||||
async run(nodeData: INodeData, input: string): Promise<string> {
|
||||
const chain = nodeData.instance as SqlDatabaseChain
|
||||
const res = await chain.run(input)
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: SqlDatabaseChain_Chains }
|
||||
@@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-sql" 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>
|
||||
<path d="M12 8a2 2 0 0 1 2 2v4a2 2 0 1 1 -4 0v-4a2 2 0 0 1 2 -2z"></path>
|
||||
<path d="M17 8v8h4"></path>
|
||||
<path d="M13 15l1 1"></path>
|
||||
<path d="M3 15a1 1 0 0 0 1 1h2a1 1 0 0 0 1 -1v-2a1 1 0 0 0 -1 -1h-2a1 1 0 0 1 -1 -1v-2a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 560 B |
@@ -0,0 +1,163 @@
|
||||
{
|
||||
"description": "Answer questions over a SQL database",
|
||||
"nodes": [
|
||||
{
|
||||
"width": 300,
|
||||
"height": 424,
|
||||
"id": "sqlDatabaseChain_0",
|
||||
"position": {
|
||||
"x": 1271.2742585099204,
|
||||
"y": 232.91561199714107
|
||||
},
|
||||
"type": "customNode",
|
||||
"data": {
|
||||
"id": "sqlDatabaseChain_0",
|
||||
"label": "Sql Database Chain",
|
||||
"name": "sqlDatabaseChain",
|
||||
"type": "SqlDatabaseChain",
|
||||
"baseClasses": ["SqlDatabaseChain", "BaseChain"],
|
||||
"category": "Chains",
|
||||
"description": "Answer questions over a SQL database",
|
||||
"inputParams": [
|
||||
{
|
||||
"label": "Database",
|
||||
"name": "database",
|
||||
"type": "options",
|
||||
"options": [
|
||||
{
|
||||
"label": "SQlite",
|
||||
"name": "sqlite"
|
||||
}
|
||||
],
|
||||
"default": "sqlite"
|
||||
},
|
||||
{
|
||||
"label": "Database File Path",
|
||||
"name": "dbFilePath",
|
||||
"type": "string",
|
||||
"placeholder": "C:/Users/chinook.db"
|
||||
}
|
||||
],
|
||||
"inputAnchors": [
|
||||
{
|
||||
"label": "LLM",
|
||||
"name": "llm",
|
||||
"type": "BaseLLM",
|
||||
"id": "sqlDatabaseChain_0-input-llm-BaseLLM"
|
||||
}
|
||||
],
|
||||
"inputs": {
|
||||
"llm": "{{openAI_0.data.instance}}",
|
||||
"database": "sqlite",
|
||||
"dbFilePath": ""
|
||||
},
|
||||
"outputAnchors": [
|
||||
{
|
||||
"id": "sqlDatabaseChain_0-output-sqlDatabaseChain-SqlDatabaseChain|BaseChain",
|
||||
"name": "sqlDatabaseChain",
|
||||
"label": "SqlDatabaseChain",
|
||||
"type": "SqlDatabaseChain | BaseChain"
|
||||
}
|
||||
],
|
||||
"selected": false
|
||||
},
|
||||
"selected": false,
|
||||
"positionAbsolute": {
|
||||
"x": 1271.2742585099204,
|
||||
"y": 232.91561199714107
|
||||
},
|
||||
"dragging": false
|
||||
},
|
||||
{
|
||||
"width": 300,
|
||||
"height": 472,
|
||||
"id": "openAI_0",
|
||||
"position": {
|
||||
"x": 867.8574087065126,
|
||||
"y": 209.58625096303308
|
||||
},
|
||||
"type": "customNode",
|
||||
"data": {
|
||||
"id": "openAI_0",
|
||||
"label": "OpenAI",
|
||||
"name": "openAI",
|
||||
"type": "OpenAI",
|
||||
"baseClasses": ["OpenAI", "BaseLLM", "BaseLanguageModel"],
|
||||
"category": "LLMs",
|
||||
"description": "Wrapper around OpenAI large language models",
|
||||
"inputParams": [
|
||||
{
|
||||
"label": "OpenAI Api Key",
|
||||
"name": "openAIApiKey",
|
||||
"type": "password"
|
||||
},
|
||||
{
|
||||
"label": "Model Name",
|
||||
"name": "modelName",
|
||||
"type": "options",
|
||||
"options": [
|
||||
{
|
||||
"label": "text-davinci-003",
|
||||
"name": "text-davinci-003"
|
||||
},
|
||||
{
|
||||
"label": "text-davinci-002",
|
||||
"name": "text-davinci-002"
|
||||
},
|
||||
{
|
||||
"label": "text-curie-001",
|
||||
"name": "text-curie-001"
|
||||
},
|
||||
{
|
||||
"label": "text-babbage-001",
|
||||
"name": "text-babbage-001"
|
||||
}
|
||||
],
|
||||
"default": "text-davinci-003",
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"label": "Temperature",
|
||||
"name": "temperature",
|
||||
"type": "number",
|
||||
"default": 0.7,
|
||||
"optional": true
|
||||
}
|
||||
],
|
||||
"inputAnchors": [],
|
||||
"inputs": {
|
||||
"modelName": "text-davinci-003",
|
||||
"temperature": "0"
|
||||
},
|
||||
"outputAnchors": [
|
||||
{
|
||||
"id": "openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel",
|
||||
"name": "openAI",
|
||||
"label": "OpenAI",
|
||||
"type": "OpenAI | BaseLLM | BaseLanguageModel"
|
||||
}
|
||||
],
|
||||
"selected": false
|
||||
},
|
||||
"selected": false,
|
||||
"positionAbsolute": {
|
||||
"x": 867.8574087065126,
|
||||
"y": 209.58625096303308
|
||||
},
|
||||
"dragging": false
|
||||
}
|
||||
],
|
||||
"edges": [
|
||||
{
|
||||
"source": "openAI_0",
|
||||
"sourceHandle": "openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel",
|
||||
"target": "sqlDatabaseChain_0",
|
||||
"targetHandle": "sqlDatabaseChain_0-input-llm-BaseLLM",
|
||||
"type": "buttonedge",
|
||||
"id": "openAI_0-openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel-sqlDatabaseChain_0-sqlDatabaseChain_0-input-llm-BaseLLM",
|
||||
"data": {
|
||||
"label": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user