diff --git a/docs/core_docs/docs/integrations/tools/duckduckgo_search.ipynb b/docs/core_docs/docs/integrations/tools/duckduckgo_search.ipynb index e0053c4cd9b1..1ff5b72ffdea 100644 --- a/docs/core_docs/docs/integrations/tools/duckduckgo_search.ipynb +++ b/docs/core_docs/docs/integrations/tools/duckduckgo_search.ipynb @@ -30,7 +30,7 @@ "### Integration details\n", "\n", "| Class | Package | [PY support](https://python.langchain.com/docs/integrations/tools/ddg/) | Package latest |\n", - "| :--- | :--- | :---: | :---: | :---: |\n", + "| :--- | :--- | :---: | :---: |\n", "| [DuckDuckGoSearch](https://api.js.langchain.com/classes/langchain_community_tools_duckduckgo_search.DuckDuckGoSearch.html) | [`@langchain/community`](https://www.npmjs.com/package/@langchain/community) | ✅ | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square&label=%20&) |\n", "\n", "## Setup\n", diff --git a/docs/core_docs/docs/integrations/tools/tavily_search.ipynb b/docs/core_docs/docs/integrations/tools/tavily_search.ipynb index ec6b12c0a0dd..ff63e76ba54c 100644 --- a/docs/core_docs/docs/integrations/tools/tavily_search.ipynb +++ b/docs/core_docs/docs/integrations/tools/tavily_search.ipynb @@ -30,7 +30,7 @@ "### Integration details\n", "\n", "| Class | Package | [PY support](https://python.langchain.com/v0.2/docs/integrations/tools/tavily_search/) | Package latest |\n", - "| :--- | :--- | :---: | :---: | :---: |\n", + "| :--- | :--- | :---: | :---: |\n", "| [TavilySearchResults](https://api.js.langchain.com/classes/langchain_community_tools_tavily_search.TavilySearchResults.html) | [`@langchain/community`](https://www.npmjs.com/package/@langchain/community) | ✅ | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square&label=%20&) |\n", "\n", "## Setup\n", diff --git a/libs/langchain-community/src/tools/duckduckgo_search.ts b/libs/langchain-community/src/tools/duckduckgo_search.ts index 70c440253a1c..7bfd04307a89 100644 --- a/libs/langchain-community/src/tools/duckduckgo_search.ts +++ b/libs/langchain-community/src/tools/duckduckgo_search.ts @@ -24,8 +24,69 @@ export interface DuckDuckGoSearchParameters extends ToolParams { const DEFAULT_MAX_RESULTS = 10; /** - * Class for interacting with the DuckDuckGo search engine - * It extends the base Tool class to perform retrieval. + * DuckDuckGo tool integration. + * + * Setup: + * Install `@langchain/community` and `duck-duck-scrape`. + * + * ```bash + * npm install @langchain/community duck-duck-scrape + * ``` + * + * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_community.tools_duckduckgo_search.DuckDuckGoSearch.html#constructor) + * + *
+ * Instantiate + * + * ```typescript + * import { DuckDuckGoSearch } from "@langchain/community/tools/duckduckgo_search"; + * + * const tool = new DuckDuckGoSearch({ maxResults: 1 }); + * ``` + *
+ * + *
+ * + *
+ * + * Invocation + * + * ```typescript + * await tool.invoke("what is the current weather in sf?"); + * + * // output: [{"title":"San Francisco, CA Current Weather | AccuWeather","link":"https://www.accuweather.com/en/us/san-francisco/94103/current-weather/347629","snippet":"Current weather in San Francisco, CA. Check current conditions in San Francisco, CA with radar, hourly, and more."}] + * ``` + *
+ * + *
+ * + *
+ * + * Invocation with tool call + * + * ```typescript + * // This is usually generated by a model, but we'll create a tool call directly for demo purposes. + * const modelGeneratedToolCall = { + * args: { + * input: "what is the current weather in sf?", + * }, + * id: "tool_call_id", + * name: tool.name, + * type: "tool_call", + * }; + * await tool.invoke(modelGeneratedToolCall); + * ``` + * + * ```text + * ToolMessage { + * "content": "[{\"title\":\"San Francisco, CA Weather Conditions | Weather Underground\",\"link\":\"https://www.wunderground.com/weather/us/ca/san-francisco\",\"snippet\":\"San Francisco Weather Forecasts. Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the San Francisco area.\"}]", + * "name": "duckduckgo-search", + * "additional_kwargs": {}, + * "response_metadata": {}, + * "tool_call_id": "tool_call_id" + * } + * ``` + *
*/ export class DuckDuckGoSearch extends Tool { private searchOptions?: SearchOptions; diff --git a/libs/langchain-community/src/tools/tavily_search.ts b/libs/langchain-community/src/tools/tavily_search.ts index a68f97d5e588..b83a042f7888 100644 --- a/libs/langchain-community/src/tools/tavily_search.ts +++ b/libs/langchain-community/src/tools/tavily_search.ts @@ -12,7 +12,70 @@ export type TavilySearchAPIRetrieverFields = ToolParams & { }; /** - * Tool for the Tavily search API. + * Tavily search API tool integration. + * + * Setup: + * Install `@langchain/community`. You'll also need an API key set as `TAVILY_API_KEY`. + * + * ```bash + * npm install @langchain/community + * ``` + * + * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_community.tools_tavily_search.TavilySearchResults.html#constructor) + * + *
+ * Instantiate + * + * ```typescript + * import { TavilySearchResults } from "@langchain/community/tools/tavily_search"; + * + * const tool = new TavilySearchResults({ + * maxResults: 2, + * // ... + * }); + * ``` + *
+ * + *
+ * + *
+ * + * Invocation + * + * ```typescript + * await tool.invoke("what is the current weather in sf?"); + * ``` + *
+ * + *
+ * + *
+ * + * Invocation with tool call + * + * ```typescript + * // This is usually generated by a model, but we'll create a tool call directly for demo purposes. + * const modelGeneratedToolCall = { + * args: { + * input: "what is the current weather in sf?", + * }, + * id: "tool_call_id", + * name: tool.name, + * type: "tool_call", + * }; + * await tool.invoke(modelGeneratedToolCall); + * ``` + * + * ```text + * ToolMessage { + * "content": "...", + * "name": "tavily_search_results_json", + * "additional_kwargs": {}, + * "response_metadata": {}, + * "tool_call_id": "tool_call_id" + * } + * ``` + *
*/ export class TavilySearchResults extends Tool { static lc_name(): string { diff --git a/libs/langchain-community/src/tools/wikipedia_query_run.ts b/libs/langchain-community/src/tools/wikipedia_query_run.ts index d0166e5c58d0..2c2f6b066761 100644 --- a/libs/langchain-community/src/tools/wikipedia_query_run.ts +++ b/libs/langchain-community/src/tools/wikipedia_query_run.ts @@ -53,16 +53,70 @@ interface PageResult { } /** - * Class for interacting with and fetching data from the Wikipedia API. It - * extends the Tool class. - * @example + * Wikipedia query tool integration. + * + * Setup: + * Install `@langchain/community`. You'll also need an API key. + * + * ```bash + * npm install @langchain/community + * ``` + * + * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_community.tools_wikipedia_query_run.WikipediaQueryRun.html#constructor) + * + *
+ * Instantiate + * * ```typescript - * const wikipediaQuery = new WikipediaQueryRun({ + * import { WikipediaQueryRun } from "@langchain/community/tools/wikipedia_query_run"; + * + * const tool = new WikipediaQueryRun({ * topKResults: 3, * maxDocContentLength: 4000, * }); - * const result = await wikipediaQuery.call("Langchain"); * ``` + *
+ * + *
+ * + *
+ * + * Invocation + * + * ```typescript + * await tool.invoke("what is the current weather in sf?"); + * ``` + *
+ * + *
+ * + *
+ * + * Invocation with tool call + * + * ```typescript + * // This is usually generated by a model, but we'll create a tool call directly for demo purposes. + * const modelGeneratedToolCall = { + * args: { + * input: "what is the current weather in sf?", + * }, + * id: "tool_call_id", + * name: tool.name, + * type: "tool_call", + * }; + * await tool.invoke(modelGeneratedToolCall); + * ``` + * + * ```text + * ToolMessage { + * "content": "...", + * "name": "wikipedia-api", + * "additional_kwargs": {}, + * "response_metadata": {}, + * "tool_call_id": "tool_call_id" + * } + * ``` + *
*/ export class WikipediaQueryRun extends Tool { static lc_name() { diff --git a/libs/langchain-exa/src/tools.ts b/libs/langchain-exa/src/tools.ts index 6bf52ad64ede..285ea7f66d0b 100644 --- a/libs/langchain-exa/src/tools.ts +++ b/libs/langchain-exa/src/tools.ts @@ -13,7 +13,75 @@ export type ExaSearchRetrieverFields< }; /** - * Tool for the Exa search API. + * Exa search tool integration. + * + * Setup: + * Install `@langchain/exa` and `exa-js`. You'll also need an API key. + * + * ```bash + * npm install @langchain/exa exa-js + * ``` + * + * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_exa.ExaSearchResults.html#constructor) + * + *
+ * Instantiate + * + * ```typescript + * import { ExaSearchResults } from "@langchain/exa"; + * import Exa from "exa-js"; + * + * const client = new Exa(process.env.EXASEARCH_API_KEY); + * + * const tool = new ExaSearchResults({ + * client, + * searchArgs: { + * numResults: 2, + * }, + * }); + * ``` + *
+ * + *
+ * + *
+ * + * Invocation + * + * ```typescript + * await tool.invoke("what is the current weather in sf?"); + * ``` + *
+ * + *
+ * + *
+ * + * Invocation with tool call + * + * ```typescript + * // This is usually generated by a model, but we'll create a tool call directly for demo purposes. + * const modelGeneratedToolCall = { + * args: { + * input: "what is the current weather in sf?", + * }, + * id: "tool_call_id", + * name: tool.name, + * type: "tool_call", + * }; + * await tool.invoke(modelGeneratedToolCall); + * ``` + * + * ```text + * ToolMessage { + * "content": "...", + * "name": "exa_search_results_json", + * "additional_kwargs": {}, + * "response_metadata": {}, + * "tool_call_id": "tool_call_id" + * } + * ``` + *
*/ export class ExaSearchResults< T extends ContentsOptions = { text: true }