aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/SearchTool.ts
diff options
context:
space:
mode:
authorJoanne <zehan_ding@brown.edu>2025-06-17 13:02:50 -0400
committerJoanne <zehan_ding@brown.edu>2025-06-17 13:02:50 -0400
commit2aa2c26b95a539d220e46b20cdfbef6ae39d6c43 (patch)
tree344a6f798f692fdd4921ab5a6762e907f5ad7b06 /src/client/views/nodes/chatbot/tools/SearchTool.ts
parent430db63077868fa54829721d6530a810aa4d4588 (diff)
parentccfdf905400cd4b81d8cde0f16bb0e15cd65621b (diff)
Merge branch 'agent-paper-main' of https://github.com/brown-dash/Dash-Web into joanne-tutorialagent
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/SearchTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/SearchTool.ts34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/client/views/nodes/chatbot/tools/SearchTool.ts b/src/client/views/nodes/chatbot/tools/SearchTool.ts
index 6a11407a5..8e6edce8c 100644
--- a/src/client/views/nodes/chatbot/tools/SearchTool.ts
+++ b/src/client/views/nodes/chatbot/tools/SearchTool.ts
@@ -3,6 +3,9 @@ import { Networking } from '../../../../Network';
import { BaseTool } from './BaseTool';
import { Observation } from '../types/types';
import { ParametersType, ToolInfo } from '../types/tool_types';
+import { Agent } from 'http';
+import { AgentDocumentManager } from '../utils/AgentDocumentManager';
+import { StrCast } from '../../../../../fields/Types';
const searchToolParams = [
{
@@ -19,18 +22,18 @@ type SearchToolParamsType = typeof searchToolParams;
const searchToolInfo: ToolInfo<SearchToolParamsType> = {
name: 'searchTool',
- citationRules: 'No citation needed. Cannot cite search results for a response. Use web scraping tools to cite specific information.',
+ citationRules: 'Always cite the search results for a response, if the search results are relevant to the response. Use the chunk_id to cite the search results. If the search results are not relevant to the response, do not cite them. ',
parameterRules: searchToolParams,
description: 'Search the web to find a wide range of websites related to a query or multiple queries. Returns a list of websites and their overviews based on the search queries.',
};
export class SearchTool extends BaseTool<SearchToolParamsType> {
- private _addLinkedUrlDoc: (url: string, id: string) => void;
+ private _docManager: AgentDocumentManager;
private _max_results: number;
- constructor(addLinkedUrlDoc: (url: string, id: string) => void, max_results: number = 4) {
+ constructor(docManager: AgentDocumentManager, max_results: number = 3) {
super(searchToolInfo);
- this._addLinkedUrlDoc = addLinkedUrlDoc;
+ this._docManager = docManager;
this._max_results = max_results;
}
@@ -45,14 +48,21 @@ export class SearchTool extends BaseTool<SearchToolParamsType> {
query,
max_results: this._max_results,
})) as { results: { url: string; snippet: string }[] };
- const data = results.map((result: { url: string; snippet: string }) => {
- const id = uuidv4();
- this._addLinkedUrlDoc(result.url, id);
- return {
- type: 'text' as const,
- text: `<chunk chunk_id="${id}" chunk_type="url"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
- };
- });
+ const data = await Promise.all(
+ results.map(async (result: { url: string; snippet: string }) => {
+ // Create a web document with the URL
+ const id = await this._docManager.createDocInDash('web', result.url, {
+ title: `Search Result: ${result.url}`,
+ text_html: result.snippet,
+ data_useCors: true,
+ });
+
+ return {
+ type: 'text' as const,
+ text: `<chunk chunk_id="${id}" chunk_type="url"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
+ };
+ })
+ );
return data;
} catch (error) {
console.log(error);