FlowiseAI
Español
Español
  • Introduction
  • Partes
    • Parte 1: Introducción
      • Recursos
    • Parte 2: Chains Avanzadas
      • Desafío 1: Traductor de Lenguas Antiguas
    • Parte 3: Gestión de Documentos y Memoria
      • Desafío 2: Chatbot Nikola Tesla
    • Parte 4: Despliegue y API
    • Parte 5: Introducción a Agentes
      • Desafíos
    • Parte 6: Agentes Avanzados
      • Desafíos
    • Parte 7: Multi-Agentes
      • Desafíos
    • Parte 8: AgentFlows
      • Desafíos
    • Parte 9: Agentes Secuenciales
      • Desafíos
    • Parte 10: Sequential Agents Avanzados
  • Recursos
    • Enlaces Útiles
    • Documentación Oficial
    • Ejemplos de Código
    • Mejores Prácticas
  • Documentación Oficial
    • Introduction
    • Primeros Pasos
    • Guía de Contribución
      • Building Node
    • Referencia de API
      • Assistants
      • Attachments
      • Chat Message
      • Chatflows
      • Document Store
      • Feedback
      • Leads
      • Ping
      • Prediction
      • Tools
      • Upsert History
      • Variables
      • Vector Upsert
    • Usar Flowise
      • Agentflows
        • Multi-Agents
        • Sequential Agents
          • Tutoriales en Video
      • API
      • Analytic
      • Almacenes de Documentos
      • Embed
      • Monitoring
      • Streaming
      • Telemetry
      • Subidas
      • Variables
      • Workspaces
      • Evaluaciones
    • Configuración
      • Auth
        • Nivel de App
        • Nivel de Chatflow
      • Databases
      • Deployment
        • AWS
        • Azure
        • Alibaba Cloud
        • Digital Ocean
        • Elestio
        • GCP
        • Hugging Face
        • Kubernetes using Helm
        • Railway
        • Render
        • Replit
        • RepoCloud
        • Sealos
        • Zeabur
      • Variables de Entorno
      • Rate Limit
      • Ejecutar Flowise detrás de proxy corporativo
      • SSO
    • Integraciones
      • LangChain
        • Agents
          • Airtable Agent
          • AutoGPT
          • BabyAGI
          • CSV Agent
          • Conversational Agent
          • Conversational Retrieval Agent
          • MistralAI Tool Agent
          • OpenAI Assistant
            • Threads
          • OpenAI Function Agent
          • OpenAI Tool Agent
          • ReAct Agent Chat
          • ReAct Agent LLM
          • Tool Agent
          • XML Agent
        • Cache
          • InMemory Cache
          • InMemory Embedding Cache
          • Momento Cache
          • Redis Cache
          • Redis Embeddings Cache
          • Upstash Redis Cache
        • Chains
          • GET API Chain
          • OpenAPI Chain
          • POST API Chain
          • Conversation Chain
          • Conversational Retrieval QA Chain
          • LLM Chain
          • Multi Prompt Chain
          • Multi Retrieval QA Chain
          • Retrieval QA Chain
          • Sql Database Chain
          • Vectara QA Chain
          • VectorDB QA Chain
        • Chat Models
          • AWS ChatBedrock
          • Azure ChatOpenAI
          • NVIDIA NIM
          • ChatAnthropic
          • ChatCohere
          • Chat Fireworks
          • ChatGoogleGenerativeAI
          • Google VertexAI
          • ChatHuggingFace
          • ChatLocalAI
          • ChatMistralAI
          • IBM Watsonx
          • ChatOllama
          • ChatOpenAI
          • ChatTogetherAI
          • GroqChat
        • Document Loaders
          • API Loader
          • Airtable
          • Apify Website Content Crawler
          • Cheerio Web Scraper
          • Confluence
          • Csv File
          • Custom Document Loader
          • Document Store
          • Docx File
          • File Loader
          • Figma
          • FireCrawl
          • Folder with Files
          • GitBook
          • Github
          • Json File
          • Json Lines File
          • Notion Database
          • Notion Folder
          • Notion Page
          • PDF Files
          • Plain Text
          • Playwright Web Scraper
          • Puppeteer Web Scraper
          • S3 File Loader
          • SearchApi For Web Search
          • SerpApi For Web Search
          • Spider Web Scraper/Crawler
          • Text File
          • Unstructured File Loader
          • Unstructured Folder Loader
          • VectorStore To Document
        • Embeddings
          • AWS Bedrock Embeddings
          • Azure OpenAI Embeddings
          • Cohere Embeddings
          • Google GenerativeAI Embeddings
          • Google VertexAI Embeddings
          • HuggingFace Inference Embeddings
          • LocalAI Embeddings
          • MistralAI Embeddings
          • Ollama Embeddings
          • OpenAI Embeddings
          • OpenAI Embeddings Custom
          • TogetherAI Embedding
          • VoyageAI Embeddings
        • LLMs
          • AWS Bedrock
          • Azure OpenAI
          • Cohere
          • GoogleVertex AI
          • HuggingFace Inference
          • Ollama
          • OpenAI
          • Replicate
        • Memory
          • Buffer Memory
          • Buffer Window Memory
          • Conversation Summary Memory
          • Conversation Summary Buffer Memory
          • DynamoDB Chat Memory
          • MongoDB Atlas Chat Memory
          • Redis-Backed Chat Memory
          • Upstash Redis-Backed Chat Memory
          • Zep Memory
        • Moderation
          • OpenAI Moderation
          • Simple Prompt Moderation
        • Output Parsers
          • CSV Output Parser
          • Custom List Output Parser
          • Structured Output Parser
          • Advanced Structured Output Parser
        • Prompts
          • Chat Prompt Template
          • Few Shot Prompt Template
          • Prompt Template
        • Record Managers
        • Retrievers
          • Custom Retriever
          • Cohere Rerank Retriever
          • Embeddings Filter Retriever
          • HyDE Retriever
          • LLM Filter Retriever
          • Multi Query Retriever
          • Prompt Retriever
          • Reciprocal Rank Fusion Retriever
          • Similarity Score Threshold Retriever
          • Vector Store Retriever
          • Voyage AI Rerank Retriever
        • Text Splitters
          • Character Text Splitter
          • Code Text Splitter
          • Html-To-Markdown Text Splitter
          • Markdown Text Splitter
          • Recursive Character Text Splitter
          • Token Text Splitter
        • Tools
          • BraveSearch API
          • Calculator
          • Chain Tool
          • Chatflow Tool
          • Custom Tool
          • Exa Search
          • Google Custom Search
          • OpenAPI Toolkit
          • Code Interpreter by E2B
          • Read File
          • Request Get
          • Request Post
          • Retriever Tool
          • SearchApi
          • SearXNG
          • Serp API
          • Serper
          • Web Browser
          • Write File
        • Vector Stores
          • AstraDB
          • Chroma
          • Elastic
          • Faiss
          • In-Memory Vector Store
          • Milvus
          • MongoDB Atlas
          • OpenSearch
          • Pinecone
          • Postgres
          • Qdrant
          • Redis
          • SingleStore
          • Supabase
          • Upstash Vector
          • Vectara
          • Weaviate
          • Zep Collection - Open Source
          • Zep Collection - Cloud
      • LiteLLM Proxy
      • LlamaIndex
        • Agents
          • OpenAI Tool Agent
          • Anthropic Tool Agent
        • Chat Models
          • AzureChatOpenAI
          • ChatAnthropic
          • ChatMistral
          • ChatOllama
          • ChatOpenAI
          • ChatTogetherAI
          • ChatGroq
        • Embeddings
          • Azure OpenAI Embeddings
          • OpenAI Embedding
        • Engine
          • Query Engine
          • Simple Chat Engine
          • Context Chat Engine
          • Sub-Question Query Engine
        • Response Synthesizer
          • Refine
          • Compact And Refine
          • Simple Response Builder
          • Tree Summarize
        • Tools
          • Query Engine Tool
        • Vector Stores
          • Pinecone
          • SimpleStore
      • Utilities
        • Custom JS Function
        • Set/Get Variable
        • If Else
        • Sticky Note
      • External Integrations
        • Zapier Zaps
    • Migration Guide
      • v1.3.0 Migration Guide
      • v1.4.3 Migration Guide
      • v2.1.4 Migration Guide
    • Use Cases
      • Calling Children Flows
      • Calling Webhook
      • Interacting with API
      • Multiple Documents QnA
      • SQL QnA
      • Upserting Data
      • Web Scrape QnA
  • Flowise
    • Flowise GitHub
    • Flowise Cloud
Powered by GitBook
On this page
  • Problema
  • Tutorial
  • Crear Tools
  • Crear Chatflow
  • Adicional
  • Pasar Session ID a la Function
  • Pasar variables a la Function
  • Sobrescribir Custom Tool
  • Importar Dependencias Externas
Edit on GitHub
  1. Documentación Oficial
  2. Integraciones
  3. LangChain
  4. Tools

Custom Tool

PreviousChatflow ToolNextExa Search

Last updated 3 months ago

Mira cómo usar custom tools

Problema

"records": [
  {
    "fields": {
      "Address": "some address",
      "Name": "some name",
      "Visited": true
    }
  }
]

Idealmente, queremos que el LLM devuelva datos estructurados adecuadamente como esto:

{
  "Address": "some address",
  "Name": "some name",
  "Visited": true
}

Así podemos extraer el valor y analizarlo en el body necesario para la API. Sin embargo, instruir al LLM para que genere el patrón exacto es difícil.

Tutorial

Objetivo: Hacer que el agent obtenga automáticamente el movimiento del precio de las acciones, recupere noticias relacionadas con las acciones y agregue un nuevo registro a Airtable.

Crear Tools

Necesitamos 3 tools para lograr el objetivo:

  • Get Stock Price Movement

  • Get Stock News

  • Add Airtable Record

Get Stock Price Movement

Crea una nueva Tool con los siguientes detalles (puedes cambiarlos como desees):

  • Name: get_stock_movers

  • Description: Get the stocks that has biggest price/volume moves, e.g. actives, gainers, losers, etc.

La descripción es una parte importante ya que ChatGPT se basa en esto para decidir cuándo usar esta tool.

    • Retorna el result al final.

El código final debería ser:

const fetch = require('node-fetch');
const url = 'https://morning-star.p.rapidapi.com/market/v2/get-movers';
const options = {
	method: 'GET',
	headers: {
		'X-RapidAPI-Key': 'replace with your api key',
		'X-RapidAPI-Host': 'morning-star.p.rapidapi.com'
	}
};

try {
	const response = await fetch(url, options);
	const result = await response.text();
	console.log(result);
	return result;
} catch (error) {
	console.error(error);
	return '';
}

Ahora puedes guardarlo.

Get Stock News

Crea una nueva Tool con los siguientes detalles (puedes cambiarlos como desees):

  • Name: get_stock_news

  • Description: Get latest news for a stock

  • Input Schema:

    • Property: performanceId

    • Type: string

    • Description: id of the stock, which is referred as performanceID in the API

    • Required: true

Input Schema le indica al LLM qué debe devolver como objeto JSON. En este caso, esperamos un objeto JSON como el siguiente:

{ "performanceId": "SOME TICKER" }
    • Retorna el result al final.

  • Luego, reemplaza el parámetro performanceId codificado en la URL: 0P0000OQN8 por la variable de propiedad especificada en Input Schema: $performanceId

  • Puedes usar cualquier propiedad especificada en Input Schema como variables en la JavaScript Function agregando el prefijo $ al principio del nombre de la variable.

Código final:

const fetch = require('node-fetch');
const url = 'https://morning-star.p.rapidapi.com/news/list?performanceId=' + $performanceId;
const options = {
	method: 'GET',
	headers: {
		'X-RapidAPI-Key': 'replace with your api key',
		'X-RapidAPI-Host': 'morning-star.p.rapidapi.com'
	}
};

try {
	const response = await fetch(url, options);
	const result = await response.text();
	console.log(result);
	return result;
} catch (error) {
	console.error(error);
	return '';
}

Ahora puedes guardarlo.

Add Airtable Record

Crea una nueva Tool con los siguientes detalles (puedes cambiarlos como desees):

  • Name: add_airtable

  • Description: Add the stock, news summary & price move to Airtable

  • Input Schema:

    • Property: stock

    • Type: string

    • Description: stock ticker

    • Required: true

    • Property: move

    • Type: string

    • Description: price move in %

    • Required: true

    • Property: news_summary

    • Type: string

    • Description: news summary of the stock

    • Required: true

ChatGPT devolverá un objeto JSON como este:

{ "stock": "SOME TICKER", "move": "20%", "news_summary": "Some summary" }

El código final debería verse como se muestra a continuación. Observa cómo pasamos $stock, $move y $news_summary como variables:

const fetch = require('node-fetch');
const baseId = 'your-base-id';
const tableId = 'your-table-id';
const token = 'your-token';

const body = {
	"records": [
		{
			"fields": {
				"stock": $stock,
				"move": $move,
				"news_summary": $news_summary,
			}
		}
	]
};

const options = {
	method: 'POST',
	headers: {
		'Authorization': `Bearer ${token}`,
		'Content-Type': 'application/json'
	},
	body: JSON.stringify(body)
};

const url = `https://api.airtable.com/v0/${baseId}/${tableId}`

try {
	const response = await fetch(url, options);
	const text = await response.text();
	return text;
} catch (error) {
	console.error(error);
	return '';
}

Ahora puedes guardarlo.

Deberías ver 3 tools creadas:

Crear Chatflow

Puedes usar la plantilla OpenAI Function Agent del marketplace, y reemplazar las tools con Custom Tool. Selecciona la tool que has creado.

Nota: OpenAI Function Agent solo soporta modelos 0613 actualmente.

Guarda el chatflow y comienza a probarlo. Para empezar, puedes intentar preguntar:

¿Qué acción tiene el mayor movimiento de precio hoy?

La acción que tiene el mayor movimiento de precio hoy es Overstock.com (OSTK) con un movimiento de precio del 17.47%.

Luego puedes hacer una pregunta de seguimiento para obtener las noticias de esa acción en particular:

¿Cuáles son las últimas noticias sobre esta acción que podrían haber causado el movimiento del precio?

Aquí están las últimas noticias sobre Overstock.com (OSTK) que podrían haber causado el movimiento del precio:

  1. Título: "Las acciones de Overstock se disparan tras la exitosa oferta de 21.5 millones por los activos de Bed Bath & Beyond" Fuente: MarketWatch Fecha de publicación: 22 de junio de 2023 Resumen: Las acciones de Overstock.com experimentaron un aumento significativo después de ganar exitosamente una oferta por los activos de Bed Bath & Beyond valorados en 21.5 millones.

  2. Título: "¿Pensando en operar opciones o acciones de Meta Platforms, Overstock.com, Walmart, Home Depot o United Parcel Service?" Fuente: PR Newswire Fecha de publicación: 22 de junio de 2023 Resumen: Este artículo de noticias discute las potenciales opciones de trading y acciones, incluyendo Overstock.com, que los inversores podrían considerar.

Ten en cuenta que estos artículos de noticias son solo para fines informativos y pueden no ser la única razón del movimiento del precio. Siempre se recomienda realizar una investigación y análisis exhaustivos antes de tomar cualquier decisión de inversión.

Por último, puedes pedirle a ChatGPT que agregue un nuevo registro a Airtable:

¿Puedes agregar un registro a Airtable con el ticker de la acción, el movimiento del precio y el resumen de noticias?

He agregado un registro a Airtable con los siguientes detalles:

Ticker de la acción: OSTK Movimiento del precio: 17.47% Resumen de noticias: Las acciones de Overstock.com experimentaron un aumento significativo después de ganar exitosamente una oferta por los activos de Bed Bath & Beyond valorados en $21.5 millones.

Adicional

Pasar Session ID a la Function

Por defecto, la Function en custom tool tiene acceso a las siguientes configuraciones de flow:

$flow.sessionId 
$flow.chatId
$flow.chatflowId
$flow.input

A continuación se muestra un ejemplo de envío del sessionId a un webhook de Discord:

const fetch = require('node-fetch');
const webhookUrl = "https://discord.com/api/webhooks/1124783587267";
const content = $content; // capturado desde input schema
const sessionId = $flow.sessionId;

const body = {
	"content": `${mycontent} and the sessionid is ${sessionId}`
};

const options = {
	method: 'POST',
	headers: {
		'Content-Type': 'application/json'
	},
	body: JSON.stringify(body)
};

const url = `${webhookUrl}?wait=true`

try {
	const response = await fetch(url, options);
	const text = await response.text();
	return text;
} catch (error) {
	console.error(error);
	return '';
}

Pasar variables a la Function

En algunos casos, te gustaría pasar variables a la función de custom tool.

Por ejemplo, estás creando un chatbot que usa una custom tool. La custom tool está ejecutando una llamada HTTP POST y se necesita una API key para una solicitud autenticada exitosa. Puedes pasarla como una variable.

Por defecto, la Function en custom tool tiene acceso a las variables:

$vars.<variable-name>

Ejemplo de cómo pasar variables en Flowise usando API y Embedded:

async function query(data) {
    const response = await fetch(
        "http://localhost:3000/api/v1/prediction/<chatflow-id>",
        {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(data)
        }
    );
    const result = await response.json();
    return result;
}

query({
    "question": "Hey, how are you?",
    "overrideConfig": {
        "vars": {
            "apiKey": "abc"
        }
    }
}).then((response) => {
    console.log(response);
});
<script type="module">
    import Chatbot from 'https://cdn.jsdelivr.net/npm/flowise-embed/dist/web.js';
    Chatbot.init({
        chatflowid: 'chatflow-id',
        apiHost: 'http://localhost:3000',
        chatflowConfig: {
          vars: {
            apiKey: 'def'
          }
        }
    });
</script>

Ejemplo de cómo recibir las variables en custom tool:

const fetch = require('node-fetch');
const webhookUrl = "https://discord.com/api/webhooks/1124783587267";
const content = $content; // capturado desde input schema
const sessionId = $flow.sessionId;
const apiKey = $vars.apiKey;

const body = {
	"content": `${mycontent} and the sessionid is ${sessionId}`
};

const options = {
	method: 'POST',
	headers: {
		'Content-Type': 'application/json',
		'Authorization': `Bearer ${apiKey}`
	},
	body: JSON.stringify(body)
};

const url = `${webhookUrl}?wait=true`

try {
	const response = await fetch(url, options);
	const text = await response.text();
	return text;
} catch (error) {
	console.error(error);
	return '';
}

Sobrescribir Custom Tool

Los siguientes parámetros pueden ser sobrescritos

Parámetro
Descripción

customToolName

nombre de la tool

customToolDesc

descripción de la tool

customToolSchema

schema de la tool

customToolFunc

función de la tool

Ejemplo de una llamada API para sobrescribir parámetros de custom tool:

async function query(data) {
    const response = await fetch(
        "http://localhost:3000/api/v1/prediction/<chatflow-id>",
        {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(data)
        }
    );
    const result = await response.json();
    return result;
}

query({
    "question": "Hey, how are you?",
    "overrideConfig": {
        "customToolName": "example_tool",
        "customToolSchema": "z.object({title: z.string()})"
    }
}).then((response) => {
    console.log(response);
});

Importar Dependencias Externas

  1. Para importar cualquier librería no soportada, puedes agregar fácilmente el nuevo paquete npm al package.json en la carpeta packages/components.

cd Flowise && cd packages && cd components
pnpm add <your-library>
cd .. && cd ..
pnpm install
pnpm build
  1. Luego, agrega las librerías importadas a la variable de entorno TOOL_FUNCTION_EXTERNAL_DEP. Consulta https://github.com/FlowiseAI/FlowiseDocs/blob/main/esp/configuration/environment-variables.md#builtin-and-external-dependencies para más detalles.

  2. Inicia la aplicación

pnpm start
  1. Entonces podrás usar la librería recién agregada en la JavaScript Function así:

const axios = require('axios')

Mira cómo agregar dependencias adicionales e importar librerías

Las funciones generalmente toman datos de entrada estructurados. Digamos que quieres que el LLM pueda llamar a la API de Airtable Create Record , los parámetros del body tienen que estar estructurados de una manera específica. Por ejemplo:

Con los nuevos modelos de , ahora es posible. gpt-4-0613 y gpt-3.5-turbo-0613 están específicamente entrenados para devolver datos estructurados. El modelo elegirá de manera inteligente generar un objeto JSON que contenga los argumentos para llamar a esas funciones.

Empecemos

JavaScript Function: Vamos a usar la API /market/v2/get-movers para obtener datos. Primero debes hacer clic en Subscribe to Test si aún no lo has hecho, luego copia el código y pégalo en JavaScript Function.

Agrega const fetch = require('node-fetch'); al principio para importar la librería. Puedes importar cualquier integrado de NodeJS y .

JavaScript Function: Vamos a usar la API /news/list para obtener los datos. Primero debes hacer clic en Subscribe to Test si aún no lo has hecho, luego copia el código y pégalo en JavaScript Function.

Agrega const fetch = require('node-fetch'); al principio para importar la librería. Puedes importar cualquier integrado de NodeJS y .

JavaScript Function: Vamos a usar para crear un nuevo registro en una tabla existente. Puedes encontrar el tableId y baseId . También necesitarás crear un token de acceso personal, encuentra cómo hacerlo .

¡Voilà! ¡Así es como puedes crear tu propia custom tool y usarla con el OpenAI Function Agent!

Puedes importar cualquier integrado de NodeJS y soportadas en la Function.

API
OpenAI Function Calling
🚀
Morning Star
módulo
librerías externas
Morning Star
módulo
librerías externas
Airtable Create Record API
aquí
aquí
🎉
🎉
módulo
librerías externas