add headers and maxlength to requests tools

This commit is contained in:
Henry
2023-05-20 13:18:53 +01:00
parent 038845c592
commit edc6f9162d
2 changed files with 62 additions and 6 deletions
@@ -1,4 +1,4 @@
import { INode } from '../../../src/Interface' import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils' import { getBaseClasses } from '../../../src/utils'
import { RequestsGetTool } from 'langchain/tools' import { RequestsGetTool } from 'langchain/tools'
@@ -10,6 +10,7 @@ class RequestsGet_Tools implements INode {
icon: string icon: string
category: string category: string
baseClasses: string[] baseClasses: string[]
inputs: INodeParams[]
constructor() { constructor() {
this.label = 'Requests Get' this.label = 'Requests Get'
@@ -19,10 +20,37 @@ class RequestsGet_Tools implements INode {
this.category = 'Tools' this.category = 'Tools'
this.description = 'Execute HTTP GET requests' this.description = 'Execute HTTP GET requests'
this.baseClasses = [this.type, ...getBaseClasses(RequestsGetTool)] 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> { async init(nodeData: INodeData): Promise<any> {
return new RequestsGetTool() 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 { getBaseClasses } from '../../../src/utils'
import { RequestsPostTool } from 'langchain/tools' import { RequestsPostTool } from 'langchain/tools'
@@ -10,6 +10,7 @@ class RequestsPost_Tools implements INode {
icon: string icon: string
category: string category: string
baseClasses: string[] baseClasses: string[]
inputs: INodeParams[]
constructor() { constructor() {
this.label = 'Requests Post' this.label = 'Requests Post'
@@ -19,10 +20,37 @@ class RequestsPost_Tools implements INode {
this.category = 'Tools' this.category = 'Tools'
this.description = 'Execute HTTP POST requests' this.description = 'Execute HTTP POST requests'
this.baseClasses = [this.type, ...getBaseClasses(RequestsPostTool)] 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> { async init(nodeData: INodeData): Promise<any> {
return new RequestsPostTool() 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()
} }
} }