22 Oct 2024 • 6 min read
Hey devs! 👋
Building the next generation of AI-powered apps just got a whole lot easier. Imagine scraping web content, transcribing audio, or generating SQL queries—all in a few lines of code. With JigsawStack’s tools now integrated into LangChain.js, you can do just that.
If you’re not familiar with it yet, LangChain.js is a framework that simplifies the development of apps powered by large language models (LLMs). Whether you’re building a simple chatbot or a multi-agent workflow, LangChain helps you organize your tools and interactions with LLMs into neat, easy-to-use utilities.
Now, JigsawStack’s suite of AI tools is just a few lines of code away in LangChain.js!
Here’s what you can do with the JigsawStack Tool Suite in LangChain.js:
JigsawStack AI Scrape: Efficiently scrape web content with AI-powered data extraction.
JigsawStack AI Search: Perform AI-driven, context-aware searches across the web.
JigsawStack Speech To Text: Transcribe audio and video using Whisper large v3 turbo AI.
JigsawStack vOCR: Extract detailed data from images using simple prompts.
JigsawStack Text To SQL: Turn natural language into precise SQL queries.
Each tool is designed to make your life as a developer easier, so you can focus on building instead of managing complex AI workflows.
Choosing the right LLM or optimizing prompts manually? Forget about it. The JigsawStack Prompt Engine automatically selects the best model and tunes your prompts for top-tier performance. You get high-quality results without fiddling with the details.
Here’s how to get started:
Create a free JigsawStack account.
Grab your API key from the JigsawStack dashboard.
Install the JigsawStack LangChain package:
npm i @langchain/jigsawstack
Start building! Here’s a quick example of how to use the 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 });
};
Output
{
"success": true,
"result": "The Leaning Tower of Pisa is a famous bell tower located in Pisa, Italy. It is one of the most iconic landmarks in the world and a symbol of Italy. Here are some interesting facts about the tower:\n\n**History:**\nThe construction of the Leaning Tower of Pisa began in 1173 and was completed in 1399. It was built as part of the Pisa Cathedral complex, which includes the Cathedral of Santa Maria Assunta, the Pisa Baptistery, and the Camposanto Monumentale.\n\n**The Leaning:**\nThe tower is famous for its unintended tilt, which is caused by the soft ground it was built on. The foundation of the tower is only 3 meters deep, and the soil beneath it is made of clay and sand, which is not stable enough to support the weight of the tower. As a result, the tower began to lean during construction, and it has continued to lean over the centuries.\n\n**The Tilt:**\nThe tower's tilt is about 3.97 degrees, which is quite significant. If it were to continue leaning at this rate, it would eventually collapse. However, in 1990, a major restoration project was undertaken to stabilize the tower and prevent it from collapsing.\n\n**Restoration:**\nThe restoration project involved removing soil from beneath the tower to reduce its weight and stabilize its foundation. The project also involved installing a system of cables and pulleys to support the tower and prevent it from collapsing. The restoration project was completed in 2001, and the tower was reopened to the public.\n\n**Interesting Facts:**\n\n* The Leaning Tower of Pisa is 55.86 meters (183 feet) tall.\n* The tower has 294 steps that lead to the top.\n* The tower is made of white marble and limestone.\n* The tower was built without the use of mortar, which is a type of cement.\n* The tower has been closed several times due to safety concerns, including a major restoration project in the 1990s.\n\n**Tourism:**\nThe Leaning Tower of Pisa is one of the most popular tourist attractions in Italy, with over 5 million visitors per year. Visitors can climb to the top of the tower for stunning views of the city and the surrounding countryside.\n\nOverall, the Leaning Tower of Pisa is an iconic landmark that is steeped in history and architecture. Its unique tilt and stunning design make it a must-see destination for anyone visiting Italy.",
}
🎯 Build Smarter Apps with JigsawStack Tools
Want to dive deeper? Here’s how to integrate JigsawStack’s tools into your LangChain.js project:
Create your JigsawStack account.
Generate your API key.
Install the LangChain integration:
npm i @langchain/jigsawstack
Use the tools:
import {
JigsawStackAIScrape,
JigsawStackAISearch,
JigsawStackSpeechToText,
JigsawStackVOCR,
JigsawStackTextToSQL,
} from "@langchain/jigsawstack";
export const run = async () => {
const aiScrapeTool = new JigsawStackAIScrape({
params: { element_prompts: [listing_titles, listing_prices] },
});
const result = await aiScrapeTool.invoke("https://www.amazon.com/s?k=playstation+5");
console.log({ result });
const aiSearchTool = new JigsawStackAISearch();
const doc = await aiSearchTool.invoke("The leaning tower of Pisa");
console.log({ doc });
const sttTool = new JigsawStackSpeechToText();
await sttTool.invoke("https://jigsawstack.com/preview/stt-example.wav");
const sqlTool = new JigsawStackTextToSQL({
params: {
sql_schema: "CREATE TABLE Transactions (transaction_id INT PRIMARY KEY, ...)",
},
});
await sqlTool.invoke(
"Generate a query to get transactions that exceed $10,000 and sort by date"
);
};
More info on installing integration packages here.
For more advanced workflows, you can combine JigsawStack tools into a LangChain agent. Want to scrape data, search for content, and transcribe audio all in one go? Done.
Here’s a quick example:
import { ChatOpenAI } from "@langchain/openai";
import { initializeAgentExecutorWithOptions } from "langchain/agents";
import {
JigsawStackAIScrape,
JigsawStackAISearch,
JigsawStackSpeechToText,
JigsawStackVOCR,
JigsawStackTextToSQL,
} from "@langchain/jigsawstack";
const model = new ChatOpenAI({ temperature: 0 });
const tools = [
new JigsawStackAIScrape(),
new JigsawStackAISearch(),
new JigsawStackSpeechToText(),
new JigsawStackVOCR(),
new JigsawStackTextToSQL(),
];
const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "zero-shot-react-description",
verbose: true,
});
const res = await executor.invoke({
input: `Find details on Kokkalo Restaurant Santorini`,
});
console.log(res.output);
Output
/*
{
"query": "Kokkalo Restaurant Santorini",
"ai_overview": "Kokkalo Restaurant, located in Fira, Santorini, offers a unique dining experience that blends traditional Greek cuisine with modern culinary trends. Here are some key details about the restaurant:\n\n- **Location**: Situated on the main road of Firostefani, Kokkalo is surrounded by the picturesque Cycladic architecture and provides stunning views of the Aegean Sea.\n- **Cuisine**: The restaurant specializes in authentic Greek dishes, crafted from high-quality, locally sourced ingredients. The menu is designed to engage all senses and features a variety of Mediterranean flavors.\n- **Ambiance**: Kokkalo boasts a chic and modern décor, creating a welcoming atmosphere for guests. The staff is known for their professionalism and attentiveness, enhancing the overall dining experience.\n- **Culinary Experience**: The name \"Kokkalo,\" meaning \"bone\" in Greek, symbolizes the strong foundation of the restaurant's culinary philosophy. Guests can expect a bold and unforgettable culinary journey.\n- **Cooking Classes**: Kokkalo also offers cooking lessons, allowing visitors to learn how to prepare traditional Greek dishes, providing a unique souvenir of their time in Santorini.\n- **Contact Information**: \n - Address: 25 Martiou str, Fira, Santorini 84 700, Cyclades, Greece\n - Phone: +30 22860 25407\n - Email: reservation@kokkalosantorini.com\n\nFor more information, you can visit their [official website](https://www.santorini-view.com/restaurants/kokkalo-restaurant/) or their [Facebook page](https://www.facebook.com/kokkalorestaurant/).",
"is_safe": true,
"results": [
{
"title": "Kokkalo restaurant, Restaurants in Firostefani Santorini Greece",
"url": "http://www.travel-to-santorini.com/restaurants/firostefani/thebonerestaurant/",
"description": "Details Contact : George Grafakos Address : Firostefani, Opposite of Fira Primary School Zipcode : 84700 City : Santorni Phone : +30 22860 25407 Send an email",
"content": null,
"site_name": "Travel-to-santorini",
"site_long_name": "travel-to-santorini.com",
"language": "en",
"is_safe": true,
"favicon": "https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://travel-to-santorini.com&size=96"
}
]
}
*/
Ready to level up your app development? It’s easy to get started. Sign up for free, grab your API key, and start using JigsawStack tools in your LangChain.js projects today. Whether you’re automating workflows, generating content, or building cutting-edge AI solutions, we can’t wait to see what you create!
Have questions or want to show off what you’ve built? Join the JigsawStack developer community on Discord and Twitter. Let’s build something amazing together!