Skip to content

Commit 0d865c7

Browse files
authored
feat(tavily-search): adding startDate and endDate params to TavilySearch tool (#8534)
2 parents f3a9881 + edb2d50 commit 0d865c7

File tree

2 files changed

+70
-26
lines changed

2 files changed

+70
-26
lines changed

libs/langchain-tavily/src/tavily-search.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ export type TavilySearchAPIRetrieverFields = ToolParams & {
105105
*/
106106
includeFavicon?: boolean;
107107

108+
/**
109+
* Filters search results to include only content published on or after this date.
110+
*
111+
* @default undefined
112+
*/
113+
startDate?: string;
114+
115+
/**
116+
* Filters search results to include only content published on or before this date.
117+
*
118+
* @default undefined
119+
*/
120+
endDate?: string;
121+
108122
/**
109123
* The name of the tool.
110124
*
@@ -348,6 +362,10 @@ export class TavilySearch extends StructuredTool<typeof inputSchema> {
348362

349363
includeFavicon?: boolean;
350364

365+
startDate?: string;
366+
367+
endDate?: string;
368+
351369
handleToolError = true;
352370

353371
apiWrapper: TavilySearchAPIWrapper;
@@ -398,6 +416,8 @@ export class TavilySearch extends StructuredTool<typeof inputSchema> {
398416
this.country = params.country;
399417
this.autoParameters = params.autoParameters;
400418
this.includeFavicon = params.includeFavicon;
419+
this.startDate = params.startDate;
420+
this.endDate = params.endDate;
401421
}
402422

403423
async _call(
@@ -439,6 +459,8 @@ export class TavilySearch extends StructuredTool<typeof inputSchema> {
439459
country: this.country,
440460
autoParameters: this.autoParameters,
441461
includeFavicon: this.includeFavicon,
462+
startDate: this.startDate,
463+
endDate: this.endDate,
442464
});
443465

444466
if (

libs/langchain-tavily/src/utils.ts

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ export type TavilySearchParamsBase = {
2121
*
2222
* @default "basic"
2323
*/
24-
search_depth?: "basic" | "advanced";
24+
searchDepth?: "basic" | "advanced";
2525

2626
/**
2727
* The number of {@link TavilySearchResult.content} chunks to retrieve from each source.
2828
* Each chunk's length is maximum 500 characters. Available only when
29-
* {@link TavilySearchParams.search_depth} is advanced.
29+
* {@link TavilySearchParams.searchDepth} is advanced.
3030
*
3131
* @default 3
3232
*/
33-
chunks_per_source?: number;
33+
chunksPerSource?: number;
3434
/**
3535
* The maximum number of search results to return.
3636
*
3737
* @default 5
3838
*/
39-
max_results?: number;
39+
maxResults?: number;
4040
/**
4141
* The time range of the search.
4242
*/
43-
time_range?: "day" | "week" | "month" | "year";
43+
timeRange?: "day" | "week" | "month" | "year";
4444
/**
4545
* Number of days back from the current date to include. Available only if topic is news.
4646
*/
@@ -51,7 +51,7 @@ export type TavilySearchParamsBase = {
5151
*
5252
* @default false
5353
*/
54-
include_answer?: boolean | "basic" | "advanced";
54+
includeAnswer?: boolean | "basic" | "advanced";
5555
/**
5656
* Include the cleaned and parsed HTML content of each search result.
5757
* "markdown" returns search result content in markdown format.
@@ -60,22 +60,44 @@ export type TavilySearchParamsBase = {
6060
*
6161
* @default false
6262
*/
63-
include_raw_content?: boolean | "markdown" | "text";
63+
includeRawContent?: boolean | "markdown" | "text";
6464
/**
6565
* A list of domains to specifically include in the search results.
6666
*/
67-
include_domains?: string[];
67+
includeDomains?: string[];
6868
/**
6969
* A list of domains to specifically exclude from the search results.
7070
*/
71-
exclude_domains?: string[];
71+
excludeDomains?: string[];
7272

7373
/**
7474
* Whether to include the favicon URL for each result.
7575
*
7676
* @default false
7777
*/
78-
include_favicon?: boolean;
78+
includeFavicon?: boolean;
79+
80+
/**
81+
* The country to search in. MUST be the full country name in lowercase
82+
* like "united states" or "united kingdom".
83+
*
84+
* @default undefined
85+
*/
86+
country?: string;
87+
88+
/**
89+
* The start date of the search.
90+
*
91+
* @default undefined
92+
*/
93+
startDate?: string;
94+
95+
/**
96+
* The end date of the search.
97+
*
98+
* @default undefined
99+
*/
100+
endDate?: string;
79101
} & Record<string, unknown>;
80102

81103
export type TavilySearchParamsWithSimpleImages = TavilySearchParamsBase & {
@@ -84,26 +106,26 @@ export type TavilySearchParamsWithSimpleImages = TavilySearchParamsBase & {
84106
*
85107
* @default false
86108
*/
87-
include_images?: boolean;
109+
includeImages?: boolean;
88110
/**
89-
* When {@link TavilySearchParams.include_images} is true, also add a descriptive text for each
111+
* When {@link TavilySearchParams.includeImages} is true, also add a descriptive text for each
90112
* image.
91113
*
92114
* @default false
93115
*/
94-
include_image_descriptions?: false;
116+
includeImageDescriptions?: boolean;
95117
};
96118

97119
export type TavilySearchParamsWithImageDescriptions = TavilySearchParamsBase & {
98120
/**
99121
* Also perform an image search and include the results in the response.
100122
*/
101-
include_images?: true;
123+
includeImages?: boolean;
102124
/**
103-
* When {@link TavilySearchParams.include_images} is true, also add a descriptive text for each
125+
* When {@link TavilySearchParams.includeImages} is true, also add a descriptive text for each
104126
* image.
105127
*/
106-
include_image_descriptions?: true;
128+
includeImageDescriptions?: true;
107129
};
108130

109131
export type TavilySearchParams =
@@ -126,22 +148,22 @@ export type TavilyExtractParams = {
126148
*
127149
* @default false
128150
*/
129-
include_images?: boolean;
151+
includeImages?: boolean;
130152
/**
131153
* The depth of the extraction process. `"advanced"` extraction retrieves more data, including
132154
* tables and embedded content, with higher success but may increase latency. The cost for
133155
* `"advanced"` extraction requests may be higher than `"basic"` extraction.
134156
*
135157
* @default "basic"
136158
*/
137-
extract_depth?: "basic" | "advanced";
159+
extractDepth?: "basic" | "advanced";
138160

139161
/**
140162
* Whether to include the favicon URL for each result.
141163
*
142164
* @default false
143165
*/
144-
include_favicon?: boolean;
166+
includeFavicon?: boolean;
145167

146168
/**
147169
* The format of the extracted web page content.
@@ -283,7 +305,7 @@ export type TavilyCrawlParams = {
283305
*
284306
* @default false
285307
*/
286-
include_favicon?: boolean;
308+
includeFavicon?: boolean;
287309
} & Record<string, unknown>;
288310

289311
/**
@@ -299,7 +321,7 @@ export type TavilyExtractResult = {
299321
*/
300322
raw_content: string;
301323
/**
302-
* This is only available if {@link TavilyExtractParams.include_images} is set to `true`. A list
324+
* This is only available if {@link TavilyExtractParams.includeImages} is set to `true`. A list
303325
* of image URLs extracted from the page.
304326
*/
305327
images: string[];
@@ -374,7 +396,7 @@ export type TavilyBaseSearchResponse = {
374396
query: string;
375397
/**
376398
* A short answer to the user's query, generated by an LLM. Included in the response only if
377-
* {@link TavilySearchParams.include_answer} is requested (i.e., set to `true`, `"basic"`, or
399+
* {@link TavilySearchParams.includeAnswer} is requested (i.e., set to `true`, `"basic"`, or
378400
* `"advanced"`).
379401
*/
380402
answer?: string;
@@ -391,12 +413,12 @@ export type TavilyBaseSearchResponse = {
391413

392414
/**
393415
* The shape of the response from the Tavily Search API when
394-
* {@link TavilySearchParams.include_image_descriptions} is true.
416+
* {@link TavilySearchParams.includeImageDescriptions} is true.
395417
*/
396418
export type TavilySearchResponseWithImageDescriptions =
397419
TavilyBaseSearchResponse & {
398420
/**
399-
* List of query-related images. If {@link TavilySearchParams.include_image_descriptions} is
421+
* List of query-related images. If {@link TavilySearchParams.includeImageDescriptions} is
400422
* `true`, each item will be an object with `url` and `description` properties. Otherwise, each
401423
* item will be a string containing the URL of the image.
402424
*/
@@ -414,11 +436,11 @@ export type TavilySearchResponseWithImageDescriptions =
414436

415437
/**
416438
* The shape of the response from the Tavily Search API when
417-
* {@link TavilySearchParams.include_image_descriptions} is `false` or unspecified.
439+
* {@link TavilySearchParams.includeImageDescriptions} is `false` or unspecified.
418440
*/
419441
export type TavilySearchResponseWithSimpleImages = TavilyBaseSearchResponse & {
420442
/**
421-
* List of query-related images. If {@link TavilySearchParams.include_image_descriptions} is
443+
* List of query-related images. If {@link TavilySearchParams.includeImageDescriptions} is
422444
* `true`, each item will be an object with `url` and `description` properties. Otherwise, each
423445
* item will be a string containing the URL of the image.
424446
*/

0 commit comments

Comments
 (0)