Skip to content

Commit

Permalink
Merge pull request #194 from FlowiseAI/feature/OpenAPIToolkit
Browse files Browse the repository at this point in the history
feature/OpenAPIToolkit
  • Loading branch information
HenryHengZJ authored May 27, 2023
2 parents aa76f8e + b8bee40 commit eee6b4d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions packages/components/nodes/tools/OpenAPIToolkit/OpenAPIToolkit.ts
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.
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@huggingface/inference": "1",
"@pinecone-database/pinecone": "^0.0.12",
"@supabase/supabase-js": "^2.21.0",
"@types/js-yaml": "^4.0.5",
"axios": "^0.27.2",
"cheerio": "^1.0.0-rc.12",
"chromadb": "^1.4.2",
Expand Down

0 comments on commit eee6b4d

Please sign in to comment.