mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 23:01:09 +03:00
update credentials
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { OpenApiToolkit } from 'langchain/agents'
|
||||
import { JsonSpec, JsonObject } from 'langchain/tools'
|
||||
import { BaseLanguageModel } from 'langchain/base_language'
|
||||
import { load } from 'js-yaml'
|
||||
import { getCredentialData, getCredentialParam } from '../../../src'
|
||||
|
||||
class OpenAPIToolkit_Tools implements INode {
|
||||
label: string
|
||||
@@ -12,6 +13,7 @@ class OpenAPIToolkit_Tools implements INode {
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
credential: INodeParams
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
@@ -21,12 +23,15 @@ class OpenAPIToolkit_Tools implements INode {
|
||||
this.icon = 'openapi.png'
|
||||
this.category = 'Tools'
|
||||
this.description = 'Load OpenAPI specification'
|
||||
this.credential = {
|
||||
label: 'Connect Credential',
|
||||
name: 'credential',
|
||||
type: 'credential',
|
||||
description: 'Only needed if the YAML OpenAPI Spec requires authentication',
|
||||
optional: true,
|
||||
credentialNames: ['openAPIAuth']
|
||||
}
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'OpenAI API Key',
|
||||
name: 'openAIApiKey',
|
||||
type: 'password'
|
||||
},
|
||||
{
|
||||
label: 'Language Model',
|
||||
name: 'model',
|
||||
@@ -42,11 +47,13 @@ class OpenAPIToolkit_Tools implements INode {
|
||||
this.baseClasses = [this.type, 'Tool']
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const openAIApiKey = nodeData.inputs?.openAIApiKey as string
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const model = nodeData.inputs?.model as BaseLanguageModel
|
||||
const yamlFileBase64 = nodeData.inputs?.yamlFile as string
|
||||
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const openAPIToken = getCredentialParam('openAPIToken', credentialData, nodeData)
|
||||
|
||||
const splitDataURI = yamlFileBase64.split(',')
|
||||
splitDataURI.pop()
|
||||
const bf = Buffer.from(splitDataURI.pop() || '', 'base64')
|
||||
@@ -56,10 +63,10 @@ class OpenAPIToolkit_Tools implements INode {
|
||||
throw new Error('Failed to load OpenAPI spec')
|
||||
}
|
||||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${openAIApiKey}`
|
||||
const headers: ICommonObject = {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
if (openAPIToken) headers.Authorization = `Bearer ${openAPIToken}`
|
||||
const toolkit = new OpenApiToolkit(new JsonSpec(data), model, headers)
|
||||
|
||||
return toolkit.tools
|
||||
|
||||
Reference in New Issue
Block a user