mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-25 09:00:58 +03:00
Merge pull request #136 from FlowiseAI/feature/RequestsTool
Feature/Requests Tools
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { INode } from '../../../src/Interface'
|
||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses } from '../../../src/utils'
|
||||
import { RequestsGetTool } from 'langchain/tools'
|
||||
|
||||
@@ -10,6 +10,7 @@ class RequestsGet_Tools implements INode {
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Requests Get'
|
||||
@@ -19,10 +20,37 @@ class RequestsGet_Tools implements INode {
|
||||
this.category = 'Tools'
|
||||
this.description = 'Execute HTTP GET requests'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(RequestsGetTool)]
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Max Output Length',
|
||||
name: 'maxOutputLength',
|
||||
type: 'number',
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Headers',
|
||||
name: 'headers',
|
||||
type: 'json',
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(): Promise<any> {
|
||||
return new RequestsGetTool()
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const headers = nodeData.inputs?.headers as string
|
||||
const maxOutputLength = nodeData.inputs?.maxOutputLength as string
|
||||
|
||||
const obj: any = {}
|
||||
if (maxOutputLength) {
|
||||
obj.maxOutputLength = parseInt(maxOutputLength, 10)
|
||||
}
|
||||
|
||||
if (headers) {
|
||||
const parsedHeaders = typeof headers === 'object' ? headers : JSON.parse(headers)
|
||||
return Object.keys(obj).length ? new RequestsGetTool(parsedHeaders, obj) : new RequestsGetTool(parsedHeaders)
|
||||
}
|
||||
return Object.keys(obj).length ? new RequestsGetTool(undefined, obj) : new RequestsGetTool()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { INode } from '../../../src/Interface'
|
||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses } from '../../../src/utils'
|
||||
import { RequestsPostTool } from 'langchain/tools'
|
||||
|
||||
@@ -10,6 +10,7 @@ class RequestsPost_Tools implements INode {
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Requests Post'
|
||||
@@ -19,10 +20,37 @@ class RequestsPost_Tools implements INode {
|
||||
this.category = 'Tools'
|
||||
this.description = 'Execute HTTP POST requests'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(RequestsPostTool)]
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Max Output Length',
|
||||
name: 'maxOutputLength',
|
||||
type: 'number',
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Headers',
|
||||
name: 'headers',
|
||||
type: 'json',
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(): Promise<any> {
|
||||
return new RequestsPostTool()
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const headers = nodeData.inputs?.headers as string
|
||||
const maxOutputLength = nodeData.inputs?.maxOutputLength as string
|
||||
|
||||
const obj: any = {}
|
||||
if (maxOutputLength) {
|
||||
obj.maxOutputLength = parseInt(maxOutputLength, 10)
|
||||
}
|
||||
|
||||
if (headers) {
|
||||
const parsedHeaders = typeof headers === 'object' ? headers : JSON.parse(headers)
|
||||
return Object.keys(obj).length ? new RequestsPostTool(parsedHeaders, obj) : new RequestsPostTool(parsedHeaders)
|
||||
}
|
||||
return Object.keys(obj).length ? new RequestsPostTool(undefined, obj) : new RequestsPostTool()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user