Documentation / @openassistant/places / webSearch
Variable: webSearch
constwebSearch:OpenAssistantTool<typeofwebSearchParameters,WebSearchLlmResult,WebSearchAdditionalData,SearchAPIToolContext>
Defined in: packages/tools/places/src/webSearch.ts:178
Web Search Tool
This tool performs web searches using the SearchAPI with Google search engine. It takes a query string and returns structured search results that can be used by LLMs and saved as JSON datasets.
Example user prompts:
- "Search for information about artificial intelligence"
- "Find the latest news about climate change"
- "Search for redfin 4440 S Oleander Dr Chandler AZ"
- "What are the best restaurants in New York?"
- "Find information about machine learning algorithms"
Example
typescript
import { webSearch, WebSearchTool } from "@openassistant/places";
import { convertToVercelAiTool, ToolCache } from '@openassistant/utils';
import { generateText } from 'ai';
// you can use ToolCache to save the web search dataset for later use
const toolResultCache = ToolCache.getInstance();
const webSearchTool: WebSearchTool = {
...webSearch,
toolContext: {
getSearchAPIKey: () => process.env.SEARCH_API_KEY!,
},
onToolCompleted: (toolCallId, additionalData) => {
toolResultCache.addDataset(toolCallId, additionalData);
},
};
generateText({
model: openai('gpt-4.1', { apiKey: key }),
prompt: 'Search for information about artificial intelligence',
tools: {
webSearch: convertToVercelAiTool(webSearchTool),
},
});