-
-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from FlowiseAI/feature/OpenAPIToolkit
feature/OpenAPIToolkit
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
packages/components/nodes/tools/OpenAPIToolkit/OpenAPIToolkit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { 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' | ||
|
||
class OpenAPIToolkit_Tools implements INode { | ||
label: string | ||
name: string | ||
description: string | ||
type: string | ||
icon: string | ||
category: string | ||
baseClasses: string[] | ||
inputs: INodeParams[] | ||
|
||
constructor() { | ||
this.label = 'OpenAPI Toolkit' | ||
this.name = 'openAPIToolkit' | ||
this.type = 'OpenAPIToolkit' | ||
this.icon = 'openapi.png' | ||
this.category = 'Tools' | ||
this.description = 'Load OpenAPI specification' | ||
this.inputs = [ | ||
{ | ||
label: 'OpenAI API Key', | ||
name: 'openAIApiKey', | ||
type: 'password' | ||
}, | ||
{ | ||
label: 'Language Model', | ||
name: 'model', | ||
type: 'BaseLanguageModel' | ||
}, | ||
{ | ||
label: 'YAML File', | ||
name: 'yamlFile', | ||
type: 'file', | ||
fileType: '.yaml' | ||
} | ||
] | ||
this.baseClasses = [this.type, 'Tool'] | ||
} | ||
|
||
async init(nodeData: INodeData): Promise<any> { | ||
const openAIApiKey = nodeData.inputs?.openAIApiKey as string | ||
const model = nodeData.inputs?.model as BaseLanguageModel | ||
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 data = load(utf8String) as JsonObject | ||
if (!data) { | ||
throw new Error('Failed to load OpenAPI spec') | ||
} | ||
|
||
const headers = { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${openAIApiKey}` | ||
} | ||
const toolkit = new OpenApiToolkit(new JsonSpec(data), model, headers) | ||
|
||
return toolkit.tools | ||
} | ||
} | ||
|
||
module.exports = { nodeClass: OpenAPIToolkit_Tools } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters