https://sdk.vercel.ai/providers/ai-sdk-providers/azure#web-search According the documentation above, ai-sdk allows web search via azure. However, google search, and chatbots do not return more details on Azure's support of web search.
import { createAzure } from '@ai-sdk/azure';import { generateText } from 'ai';
const endpoint = process.env.AZURE_OPENAI_ENDPOINT;const apiKey = process.env.AZURE_OPENAI_API_KEY;const deploymentName = process.env.AZURE_OPENAI_DEPLOYMENT;
if (!endpoint || !apiKey || !deploymentName) { console.error( 'Error: One or more required env vars are missing: AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_KEY, AZURE_OPENAI_DEPLOYMENT', ); process.exit(1);}
// Extract resource name from endpointconst resourceName = endpoint.replace(/^https?:\/\//, '').split('.')[0];
const azure = createAzure({ resourceName, apiKey,});
const prompt = process.argv.slice(2).join(' ');if (!prompt) { console.error('Usage: pnpm tsx azure-chat.ts "Your prompt here"'); process.exit(1);}
async function main() { try { const { text } = await generateText({ model: azure.responses(deploymentName as string), prompt, // tools: { // web_search_preview: azure.tools.webSearchPreview({ // // optional configuration: // searchContextSize: 'high', // userLocation: { // type: 'approximate', // city: 'San Francisco', // region: 'California', // }, // }), // // Force web search tool: // toolChoice: { type: 'tool', toolName: 'web_search_preview' }, // // You can add providerOptions here if needed // }, }); console.log('Azure OpenAI response:', text); } catch (err) { console.error('Error communicating with Azure OpenAI:', err); process.exit(1); }}
main();
My above code works. The commented part is copied from the documentation. But if I uncomment it , error occurs.
TypeError: undefined is not an object (evaluating 'azure.tools.webSearchPreview')
/azure": "^1.3.19", "ai": "4.3.4",