mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 09:01:06 +03:00
@@ -0,0 +1,95 @@
|
|||||||
|
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||||
|
import { APIChain, createOpenAPIChain } from 'langchain/chains'
|
||||||
|
import { CustomChainHandler, getBaseClasses } from '../../../src/utils'
|
||||||
|
import { ChatOpenAI } from 'langchain/chat_models/openai'
|
||||||
|
|
||||||
|
class OpenApiChain_Chains implements INode {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
type: string
|
||||||
|
icon: string
|
||||||
|
category: string
|
||||||
|
baseClasses: string[]
|
||||||
|
description: string
|
||||||
|
inputs: INodeParams[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'OpenAPI Chain'
|
||||||
|
this.name = 'openApiChain'
|
||||||
|
this.type = 'openApiChain'
|
||||||
|
this.icon = 'openapi.png'
|
||||||
|
this.category = 'Chains'
|
||||||
|
this.description = 'Chain to run queries against OpenAPI'
|
||||||
|
this.baseClasses = [this.type, ...getBaseClasses(APIChain)]
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'ChatOpenAI Model',
|
||||||
|
name: 'model',
|
||||||
|
type: 'ChatOpenAI'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'YAML Link',
|
||||||
|
name: 'yamlLink',
|
||||||
|
type: 'string',
|
||||||
|
placeholder: 'https://api.speak.com/openapi.yaml',
|
||||||
|
description: 'If YAML link is provided, uploaded YAML File will be ignored and YAML link will be used instead'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'YAML File',
|
||||||
|
name: 'yamlFile',
|
||||||
|
type: 'file',
|
||||||
|
fileType: '.yaml',
|
||||||
|
description: 'If YAML link is provided, uploaded YAML File will be ignored and YAML link will be used instead'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Headers',
|
||||||
|
name: 'headers',
|
||||||
|
type: 'json',
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
async init(nodeData: INodeData): Promise<any> {
|
||||||
|
return await initChain(nodeData)
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
||||||
|
const chain = await initChain(nodeData)
|
||||||
|
if (options.socketIO && options.socketIOClientId) {
|
||||||
|
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
|
||||||
|
const res = await chain.run(input, [handler])
|
||||||
|
return res
|
||||||
|
} else {
|
||||||
|
const res = await chain.run(input)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const initChain = async (nodeData: INodeData) => {
|
||||||
|
const model = nodeData.inputs?.model as ChatOpenAI
|
||||||
|
const headers = nodeData.inputs?.headers as string
|
||||||
|
const yamlLink = nodeData.inputs?.yamlLink as string
|
||||||
|
const yamlFileBase64 = nodeData.inputs?.yamlFile as string
|
||||||
|
|
||||||
|
let yamlString = ''
|
||||||
|
|
||||||
|
if (yamlLink) {
|
||||||
|
yamlString = yamlLink
|
||||||
|
} else {
|
||||||
|
const splitDataURI = yamlFileBase64.split(',')
|
||||||
|
splitDataURI.pop()
|
||||||
|
const bf = Buffer.from(splitDataURI.pop() || '', 'base64')
|
||||||
|
yamlString = bf.toString('utf-8')
|
||||||
|
}
|
||||||
|
|
||||||
|
return await createOpenAPIChain(yamlString, {
|
||||||
|
llm: model,
|
||||||
|
headers: typeof headers === 'object' ? headers : headers ? JSON.parse(headers) : {},
|
||||||
|
verbose: process.env.DEBUG === 'true' ? true : false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { nodeClass: OpenApiChain_Chains }
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
@@ -1,5 +1,5 @@
|
|||||||
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||||
import { SqlDatabaseChain, SqlDatabaseChainInput } from 'langchain/chains'
|
import { SqlDatabaseChain, SqlDatabaseChainInput } from 'langchain/chains/sql_db'
|
||||||
import { CustomChainHandler, getBaseClasses } from '../../../src/utils'
|
import { CustomChainHandler, getBaseClasses } from '../../../src/utils'
|
||||||
import { DataSource } from 'typeorm'
|
import { DataSource } from 'typeorm'
|
||||||
import { SqlDatabase } from 'langchain/sql_db'
|
import { SqlDatabase } from 'langchain/sql_db'
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
"form-data": "^4.0.0",
|
"form-data": "^4.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.96",
|
"langchain": "^0.0.104",
|
||||||
"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