Update OpenAPIChain.ts
This commit is contained in:
parent
6166074e07
commit
45792665df
|
|
@ -27,11 +27,19 @@ class OpenApiChain_Chains implements INode {
|
||||||
name: 'model',
|
name: 'model',
|
||||||
type: 'ChatOpenAI'
|
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',
|
label: 'YAML File',
|
||||||
name: 'yamlFile',
|
name: 'yamlFile',
|
||||||
type: 'file',
|
type: 'file',
|
||||||
fileType: '.yaml'
|
fileType: '.yaml',
|
||||||
|
description: 'If YAML link is provided, uploaded YAML File will be ignored and YAML link will be used instead'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Headers',
|
label: 'Headers',
|
||||||
|
|
@ -44,34 +52,13 @@ class OpenApiChain_Chains implements INode {
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(nodeData: INodeData): Promise<any> {
|
async init(nodeData: INodeData): Promise<any> {
|
||||||
const model = nodeData.inputs?.model as ChatOpenAI
|
return await initChain(nodeData)
|
||||||
const headers = nodeData.inputs?.headers as string
|
|
||||||
const yamlFileBase64 = nodeData.inputs?.yamlFile as string
|
|
||||||
const splitDataURI = yamlFileBase64.split(',')
|
|
||||||
splitDataURI.pop()
|
|
||||||
const bf = Buffer.from(splitDataURI.pop() || '', 'base64')
|
|
||||||
const utf8String = bf.toString('utf-8')
|
|
||||||
const chain = await createOpenAPIChain(utf8String, {
|
|
||||||
llm: model,
|
|
||||||
headers: typeof headers === 'object' ? headers : headers ? JSON.parse(headers) : {}
|
|
||||||
})
|
|
||||||
return chain
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
||||||
const model = nodeData.inputs?.model as ChatOpenAI
|
const chain = await initChain(nodeData)
|
||||||
const headers = nodeData.inputs?.headers as string
|
|
||||||
const yamlFileBase64 = nodeData.inputs?.yamlFile as string
|
|
||||||
const splitDataURI = yamlFileBase64.split(',')
|
|
||||||
splitDataURI.pop()
|
|
||||||
const bf = Buffer.from(splitDataURI.pop() || '', 'base64')
|
|
||||||
const utf8String = bf.toString('utf-8')
|
|
||||||
const chain = await createOpenAPIChain(utf8String, {
|
|
||||||
llm: model,
|
|
||||||
headers: typeof headers === 'object' ? headers : headers ? JSON.parse(headers) : {}
|
|
||||||
})
|
|
||||||
if (options.socketIO && options.socketIOClientId) {
|
if (options.socketIO && options.socketIOClientId) {
|
||||||
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId, 2)
|
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
|
||||||
const res = await chain.run(input, [handler])
|
const res = await chain.run(input, [handler])
|
||||||
return res
|
return res
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -81,4 +68,28 @@ class OpenApiChain_Chains implements INode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 }
|
module.exports = { nodeClass: OpenApiChain_Chains }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue