> ## Documentation Index
> Fetch the complete documentation index at: https://jigsaw-13.mintlify.app/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain

> Unlock the Power of the JigsawStack on LangChain!

<img className="mx-auto" src="https://mintcdn.com/jigsaw-13/Yr5ohXUpCUOk0bXg/images/langchain.png?fit=max&auto=format&n=Yr5ohXUpCUOk0bXg&q=85&s=eef9879772e79199b38ea73be52c117e" alt="Powered by LangChain" height="300" width="300" data-path="images/langchain.png" />

The JigsawStack Tool provides your agent with several capabilities:

* **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

1. **Set up an [account](https://jigsawstack.com/)**: Get started for free
2. **Create and retrieve your API key**:

```bash theme={null}
export JIGSAWSTACK_API_KEY="your-api-key"
```

## Installation

Install the JigsawStack integration package for your project:

```bash theme={null}
# npm
npm install @langchain/jigsawstack

# Yarn
yarn add @langchain/jigsawstack

# pnpm
pnpm add @langchain/jigsawstack
```

## Usage: Standalone

### Example: Using Other JigsawStack Tools

```javascript theme={null}
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

```javascript theme={null}
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);
```

<Info>
  For more details, visit the [LangChain
  documentation](https://js.langchain.com/docs/integrations/llms/jigsawstack/).
</Info>
