mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 03:01:10 +03:00
Chore/Update issue templates and add new tools (#4687)
* Enhancement: Update issue templates and add new tools - Updated bug report template to include a default label of 'bug'. - Updated feature request template to include a default label of 'enhancement'. - Added new credential class for Agentflow API. - Enhanced Agent and HTTP nodes to improve tool management and error handling. - Added deprecation badges to several agent and chain classes. - Introduced new tools for handling requests (GET, POST, DELETE, PUT) with improved error handling. - Added new chatflows and agentflows for various use cases, including document QnA and translation. - Updated UI components for better handling of agent flows and marketplace interactions. - Refactored utility functions for improved functionality and clarity. * Refactor: Remove beta badge and streamline template title assignment - Removed the 'BETA' badge from the ExtractMetadataRetriever class. - Simplified the title assignment in the agentflowv2 generator by using a variable instead of inline string manipulation.
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses, stripHTMLFromToolInput } from '../../../src/utils'
|
||||
import { RequestParameters, desc, RequestsPutTool } from './core'
|
||||
|
||||
const codeExample = `{
|
||||
"name": {
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "Name of the item"
|
||||
},
|
||||
"date": {
|
||||
"type": "string",
|
||||
"description": "Date of the item"
|
||||
}
|
||||
}`
|
||||
|
||||
class RequestsPut_Tools implements INode {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
description: string
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Requests Put'
|
||||
this.name = 'requestsPut'
|
||||
this.version = 1.0
|
||||
this.type = 'RequestsPut'
|
||||
this.icon = 'put.png'
|
||||
this.category = 'Tools'
|
||||
this.description = 'Execute HTTP PUT requests'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(RequestsPutTool)]
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'URL',
|
||||
name: 'requestsPutUrl',
|
||||
type: 'string',
|
||||
acceptVariable: true
|
||||
},
|
||||
{
|
||||
label: 'Name',
|
||||
name: 'requestsPutName',
|
||||
type: 'string',
|
||||
default: 'requests_put',
|
||||
description: 'Name of the tool',
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Description',
|
||||
name: 'requestsPutDescription',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
default: desc,
|
||||
description: 'Describe to LLM when it should use this tool',
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Headers',
|
||||
name: 'requestsPutHeaders',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
acceptVariable: true,
|
||||
additionalParams: true,
|
||||
optional: true,
|
||||
placeholder: `{
|
||||
"Authorization": "Bearer <token>"
|
||||
}`
|
||||
},
|
||||
{
|
||||
label: 'Body',
|
||||
name: 'requestPutBody',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
description: 'JSON body for the PUT request. This will override the body generated by the LLM',
|
||||
additionalParams: true,
|
||||
acceptVariable: true,
|
||||
optional: true,
|
||||
placeholder: `{
|
||||
"name": "John Doe",
|
||||
"age": 30
|
||||
}`
|
||||
},
|
||||
{
|
||||
label: 'Body Schema',
|
||||
name: 'requestsPutBodySchema',
|
||||
type: 'code',
|
||||
description: 'Description of the available body params to enable LLM to figure out which body params to use',
|
||||
placeholder: `{
|
||||
"name": {
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "Name of the item"
|
||||
},
|
||||
"date": {
|
||||
"type": "string",
|
||||
"description": "Date of the item"
|
||||
}
|
||||
}`,
|
||||
optional: true,
|
||||
hideCodeExecute: true,
|
||||
additionalParams: true,
|
||||
codeExample: codeExample
|
||||
},
|
||||
{
|
||||
label: 'Max Output Length',
|
||||
name: 'requestsPutMaxOutputLength',
|
||||
type: 'number',
|
||||
description: 'Max length of the output. Remove this if you want to return the entire response',
|
||||
default: '2000',
|
||||
step: 1,
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const headers = (nodeData.inputs?.headers as string) || (nodeData.inputs?.requestsPutHeaders as string)
|
||||
const url = (nodeData.inputs?.url as string) || (nodeData.inputs?.requestsPutUrl as string)
|
||||
const name = (nodeData.inputs?.name as string) || (nodeData.inputs?.requestsPutName as string)
|
||||
const description = (nodeData.inputs?.description as string) || (nodeData.inputs?.requestsPutDescription as string)
|
||||
const body = (nodeData.inputs?.body as string) || (nodeData.inputs?.requestPutBody as string)
|
||||
const bodySchema = nodeData.inputs?.requestsPutBodySchema as string
|
||||
const maxOutputLength = (nodeData.inputs?.maxOutputLength as string) || (nodeData.inputs?.requestsPutMaxOutputLength as string)
|
||||
|
||||
const obj: RequestParameters = {}
|
||||
if (url) obj.url = stripHTMLFromToolInput(url)
|
||||
if (description) obj.description = description
|
||||
if (name)
|
||||
obj.name = name
|
||||
.toLowerCase()
|
||||
.replace(/ /g, '_')
|
||||
.replace(/[^a-z0-9_-]/g, '')
|
||||
if (bodySchema) obj.bodySchema = stripHTMLFromToolInput(bodySchema)
|
||||
if (maxOutputLength) obj.maxOutputLength = parseInt(maxOutputLength, 10)
|
||||
if (headers) {
|
||||
const parsedHeaders = typeof headers === 'object' ? headers : JSON.parse(stripHTMLFromToolInput(headers))
|
||||
obj.headers = parsedHeaders
|
||||
}
|
||||
if (body) {
|
||||
const parsedBody = typeof body === 'object' ? body : JSON.parse(body)
|
||||
obj.body = parsedBody
|
||||
}
|
||||
|
||||
return new RequestsPutTool(obj)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: RequestsPut_Tools }
|
||||
@@ -0,0 +1,145 @@
|
||||
import { z } from 'zod'
|
||||
import fetch from 'node-fetch'
|
||||
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
|
||||
|
||||
export const desc = `Use this when you want to execute a PUT request to update or replace a resource.`
|
||||
|
||||
export interface Headers {
|
||||
[key: string]: string
|
||||
}
|
||||
|
||||
export interface Body {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export interface RequestParameters {
|
||||
headers?: Headers
|
||||
body?: Body
|
||||
url?: string
|
||||
description?: string
|
||||
name?: string
|
||||
bodySchema?: string
|
||||
maxOutputLength?: number
|
||||
}
|
||||
|
||||
// Base schema for PUT request
|
||||
const createRequestsPutSchema = (bodySchema?: string) => {
|
||||
// If bodySchema is provided, parse it and add dynamic body params
|
||||
if (bodySchema) {
|
||||
try {
|
||||
const parsedSchema = JSON.parse(bodySchema)
|
||||
const bodyParamsObject: Record<string, z.ZodTypeAny> = {}
|
||||
|
||||
Object.entries(parsedSchema).forEach(([key, config]: [string, any]) => {
|
||||
let zodType: z.ZodTypeAny = z.string()
|
||||
|
||||
// Handle different types
|
||||
if (config.type === 'number') {
|
||||
zodType = z.number()
|
||||
} else if (config.type === 'boolean') {
|
||||
zodType = z.boolean()
|
||||
} else if (config.type === 'object') {
|
||||
zodType = z.record(z.any())
|
||||
} else if (config.type === 'array') {
|
||||
zodType = z.array(z.any())
|
||||
}
|
||||
|
||||
// Add description
|
||||
if (config.description) {
|
||||
zodType = zodType.describe(config.description)
|
||||
}
|
||||
|
||||
// Make optional if not required
|
||||
if (!config.required) {
|
||||
zodType = zodType.optional()
|
||||
}
|
||||
|
||||
bodyParamsObject[key] = zodType
|
||||
})
|
||||
|
||||
if (Object.keys(bodyParamsObject).length > 0) {
|
||||
return z.object({
|
||||
body: z.object(bodyParamsObject).describe('Request body parameters')
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to parse bodySchema:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to generic body
|
||||
return z.object({
|
||||
body: z.record(z.any()).optional().describe('Optional body data to include in the request')
|
||||
})
|
||||
}
|
||||
|
||||
export class RequestsPutTool extends DynamicStructuredTool {
|
||||
url = ''
|
||||
maxOutputLength = Infinity
|
||||
headers = {}
|
||||
body = {}
|
||||
bodySchema?: string
|
||||
|
||||
constructor(args?: RequestParameters) {
|
||||
const schema = createRequestsPutSchema(args?.bodySchema)
|
||||
|
||||
const toolInput = {
|
||||
name: args?.name || 'requests_put',
|
||||
description: args?.description || desc,
|
||||
schema: schema,
|
||||
baseUrl: '',
|
||||
method: 'PUT',
|
||||
headers: args?.headers || {}
|
||||
}
|
||||
super(toolInput)
|
||||
this.url = args?.url ?? this.url
|
||||
this.headers = args?.headers ?? this.headers
|
||||
this.body = args?.body ?? this.body
|
||||
this.maxOutputLength = args?.maxOutputLength ?? this.maxOutputLength
|
||||
this.bodySchema = args?.bodySchema
|
||||
}
|
||||
|
||||
/** @ignore */
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg }
|
||||
|
||||
try {
|
||||
const inputUrl = this.url
|
||||
if (!inputUrl) {
|
||||
throw new Error('URL is required for PUT request')
|
||||
}
|
||||
|
||||
let inputBody = {
|
||||
...this.body
|
||||
}
|
||||
|
||||
if (this.bodySchema && params.body && Object.keys(params.body).length > 0) {
|
||||
inputBody = {
|
||||
...inputBody,
|
||||
...params.body
|
||||
}
|
||||
}
|
||||
|
||||
const requestHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
...(params.headers || {}),
|
||||
...this.headers
|
||||
}
|
||||
|
||||
const res = await fetch(inputUrl, {
|
||||
method: 'PUT',
|
||||
headers: requestHeaders,
|
||||
body: JSON.stringify(inputBody)
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP Error ${res.status}: ${res.statusText}`)
|
||||
}
|
||||
|
||||
const text = await res.text()
|
||||
return text.slice(0, this.maxOutputLength)
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to make PUT request: ${error instanceof Error ? error.message : 'Unknown error'}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.6 KiB |
Reference in New Issue
Block a user