Skip to content

Commit

Permalink
Adds tool docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Aug 13, 2024
1 parent bf5c62a commit d40bb7e
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/core_docs/docs/integrations/tools/tavily_search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
65 changes: 63 additions & 2 deletions libs/langchain-community/src/tools/duckduckgo_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
* <details open>
* <summary><strong>Instantiate</strong></summary>
*
* ```typescript
* import { DuckDuckGoSearch } from "@langchain/community/tools/duckduckgo_search";
*
* const tool = new DuckDuckGoSearch({ maxResults: 1 });
* ```
* </details>
*
* <br />
*
* <details>
*
* <summary><strong>Invocation</strong></summary>
*
* ```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":"<b>Current</b> <b>weather</b> <b>in</b> San Francisco, CA. Check <b>current</b> conditions in San Francisco, CA with radar, hourly, and more."}]
* ```
* </details>
*
* <br />
*
* <details>
*
* <summary><strong>Invocation with tool call</strong></summary>
*
* ```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 <b>Weather</b> Forecasts. <b>Weather</b> Underground provides local & long-range <b>weather</b> forecasts, weatherreports, maps & tropical <b>weather</b> conditions for the San Francisco area.\"}]",
* "name": "duckduckgo-search",
* "additional_kwargs": {},
* "response_metadata": {},
* "tool_call_id": "tool_call_id"
* }
* ```
* </details>
*/
export class DuckDuckGoSearch extends Tool {
private searchOptions?: SearchOptions;
Expand Down
65 changes: 64 additions & 1 deletion libs/langchain-community/src/tools/tavily_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
* <details open>
* <summary><strong>Instantiate</strong></summary>
*
* ```typescript
* import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
*
* const tool = new TavilySearchResults({
* maxResults: 2,
* // ...
* });
* ```
* </details>
*
* <br />
*
* <details>
*
* <summary><strong>Invocation</strong></summary>
*
* ```typescript
* await tool.invoke("what is the current weather in sf?");
* ```
* </details>
*
* <br />
*
* <details>
*
* <summary><strong>Invocation with tool call</strong></summary>
*
* ```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"
* }
* ```
* </details>
*/
export class TavilySearchResults extends Tool {
static lc_name(): string {
Expand Down
64 changes: 59 additions & 5 deletions libs/langchain-community/src/tools/wikipedia_query_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
* <details open>
* <summary><strong>Instantiate</strong></summary>
*
* ```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");
* ```
* </details>
*
* <br />
*
* <details>
*
* <summary><strong>Invocation</strong></summary>
*
* ```typescript
* await tool.invoke("what is the current weather in sf?");
* ```
* </details>
*
* <br />
*
* <details>
*
* <summary><strong>Invocation with tool call</strong></summary>
*
* ```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"
* }
* ```
* </details>
*/
export class WikipediaQueryRun extends Tool {
static lc_name() {
Expand Down
70 changes: 69 additions & 1 deletion libs/langchain-exa/src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
* <details open>
* <summary><strong>Instantiate</strong></summary>
*
* ```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,
* },
* });
* ```
* </details>
*
* <br />
*
* <details>
*
* <summary><strong>Invocation</strong></summary>
*
* ```typescript
* await tool.invoke("what is the current weather in sf?");
* ```
* </details>
*
* <br />
*
* <details>
*
* <summary><strong>Invocation with tool call</strong></summary>
*
* ```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"
* }
* ```
* </details>
*/
export class ExaSearchResults<
T extends ContentsOptions = { text: true }
Expand Down

0 comments on commit d40bb7e

Please sign in to comment.