LangChain.js now supports calling JigsawStack Prompt Engine and more through the JigsawStack Tool.
The JigsawStack Tool provides your agent with several capabilities:
- JigsawStack Prompt Engine: Use JigsawStack’s advanced prompt engine to interact with large language models.
- JigsawStackAIScrape: Scrape web content with AI-powered precision.
- JigsawStackAISearch: Perform AI-powered web searches for high-quality results.
- JigsawStackSpeechToText: Transcribe audio or video using the powerful large V3 Whisper model.
- JigsawStackVOCR: Recognize and extract data from images via AI prompts.
- JigsawStackTextToSQL: Generate SQL queries from natural language text.
Setup
- Set up an account: Get started for free
- Create and retrieve your API key:
export JIGSAWSTACK_API_KEY="your-api-key"
Installation
Install the JigsawStack integration package for your project:
# npm
npm install @langchain/jigsawstack
# Yarn
yarn add @langchain/jigsawstack
# pnpm
pnpm add @langchain/jigsawstack
Usage: Standalone
Example 1: Using the JigsawStack Prompt Engine
import { JigsawStackPromptEngine } from "@langchain/jigsawstack";
export const run = async () => {
const model = new JigsawStackPromptEngine();
const res = await model.invoke(
"Tell me about the leaning tower of pisa?\nAnswer:",
);
console.log({ res });
};
import {
JigsawStackAIScrape,
JigsawStackAISearch,
JigsawStackSpeechToText,
JigsawStackVOCR,
JigsawStackTextToSQL,
} from "@langchain/jigsawstack";
// Example of AI Scrape Tool
const aiScrapeTool = new JigsawStackAIScrape({
params: {
element_prompts: ["Pro plan"],
},
});
const scrapeResult = await aiScrapeTool.invoke(
"https://jigsawstack.com/pricing",
);
console.log({ scrapeResult });
// Example of AI Search Tool
const aiSearchTool = new JigsawStackAISearch();
const searchResult = await aiSearchTool.invoke("The leaning tower of Pisa");
console.log({ searchResult });
// Example of VOCR Tool
const vocrTool = new JigsawStackVOCR({
params: {
prompt: "Describe the image in detail",
},
});
const vocrResult = await vocrTool.invoke("https://link-to-image.jpg");
console.log({ vocrResult });
// Example of Speech-to-Text Tool
const sttTool = new JigsawStackSpeechToText();
await sttTool.invoke("https://link-to-video.mp4");
// Example of Text-to-SQL Tool
const sqlTool = new JigsawStackTextToSQL({
params: {
sql_schema:
"CREATE TABLE Transactions (transaction_id INT PRIMARY KEY, user_id INT NOT NULL, ... )",
},
});
const sqlResult = await sqlTool.invoke(
"Generate a query to get transactions exceeding $10,000.",
);
console.log({ sqlResult });
Usage: In an Agent
import { ChatOpenAI } from "@langchain/openai";
import { initializeAgentExecutorWithOptions } from "langchain/agents";
import {
JigsawStackAIScrape,
JigsawStackAISearch,
JigsawStackVOCR,
JigsawStackSpeechToText,
JigsawStackTextToSQL,
} from "@langchain/jigsawstack";
const model = new ChatOpenAI({ temperature: 0 });
// Add the necessary tools
const tools = [
new JigsawStackAIScrape(),
new JigsawStackAISearch(),
new JigsawStackVOCR(),
new JigsawStackSpeechToText(),
new JigsawStackTextToSQL(),
];
const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "zero-shot-react-description",
verbose: true,
});
const res = await executor.invoke({
input: "Kokkalo Restaurant Santorini",
});
console.log(res.output);