createWebSearchPreProcessor
createWebSearchPreProcessor(
options:WebSearchPreProcessorOptions):PromptPreProcessor
Defined in: src/lib/chat/webSearchClassifier.ts:140
Build a pre-processor that runs web-search classification on the
shared embedding provided by runToolLoop, and — if the classifier
decides a search is warranted — invokes the caller-supplied
fetchSearchResults and injects the result into the conversation.
Parameters
| Parameter | Type |
|---|---|
|
|
Returns
Examples
import { runToolLoop, createWebSearchPreProcessor } from "@anuma/sdk/server";
const webSearch = createWebSearchPreProcessor({
fetchSearchResults: async (prompt, { signal }) => {
const res = await mySearchProvider.query(prompt, { signal });
return res.results.map((r) => `- ${r.title}: ${r.snippet}`).join("\n");
},
});
await runToolLoop({
messages,
model,
token,
preProcessors: [webSearch],
});const observer = createWebSearchPreProcessor({
onClassification: ({ needsWebSearch, searchScore, noSearchScore }) => {
metrics.record({ needsWebSearch, searchScore, noSearchScore });
},
});const webSearch = createWebSearchPreProcessor({
fetchSearchResults: async (prompt, { signal }) => {
const results = await mySearchProvider.query(prompt, { signal });
return [
{
role: "system",
content: [{ type: "text", text: `Search results for "${prompt}":\n${formatResults(results)}` }],
},
];
},
});Last updated on