Skip to content

Commit 5c6f391

Browse files
feat(community): TavilySearchResults: Add apiUrl field (#7890)
Co-authored-by: Jacob Lee <[email protected]>
1 parent 3816ede commit 5c6f391

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

libs/langchain-community/src/tools/tavily_search.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ export type TavilySearchAPIRetrieverFields = ToolParams & {
8686
* @default 3
8787
*/
8888
days?: number;
89+
90+
/**
91+
* The base API url used for the Tavily Search API.
92+
*
93+
* @default "https://api.tavily.com"
94+
*/
95+
apiUrl?: string;
8996
};
9097

9198
/**
@@ -188,6 +195,8 @@ export class TavilySearchResults extends Tool {
188195

189196
protected days?: number;
190197

198+
protected apiUrl?: string;
199+
191200
constructor(fields?: TavilySearchAPIRetrieverFields) {
192201
super(fields);
193202
this.maxResults = fields?.maxResults ?? this.maxResults;
@@ -204,6 +213,7 @@ export class TavilySearchResults extends Tool {
204213
this.searchDepth = fields?.searchDepth ?? this.searchDepth;
205214
this.topic = fields?.topic ?? this.topic;
206215
this.days = fields?.days ?? this.days;
216+
this.apiUrl = fields?.apiUrl ?? "https://api.tavily.com";
207217

208218
if (this.apiKey === undefined) {
209219
throw new Error(
@@ -231,7 +241,7 @@ export class TavilySearchResults extends Tool {
231241
days: this.days,
232242
};
233243

234-
const response = await fetch("https://api.tavily.com/search", {
244+
const response = await fetch(`${this.apiUrl}/search`, {
235245
method: "POST",
236246
headers: {
237247
"content-type": "application/json",

0 commit comments

Comments
 (0)