Skip to content

Commit c7b6d04

Browse files
committed
feat: add web search tool example
1 parent 23235ec commit c7b6d04

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

app/(chat)/api/chat/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { getWeather } from '@/lib/ai/tools/get-weather';
2525
import { isProductionEnvironment } from '@/lib/constants';
2626
import { NextResponse } from 'next/server';
2727
import { myProvider } from '@/lib/ai/providers';
28+
import { openai } from '@ai-sdk/openai';
2829

2930
export const maxDuration = 60;
3031

@@ -85,6 +86,7 @@ export async function POST(request: Request) {
8586
'createDocument',
8687
'updateDocument',
8788
'requestSuggestions',
89+
'web_search_preview'
8890
],
8991
experimental_transform: smoothStream({ chunking: 'word' }),
9092
experimental_generateMessageId: generateUUID,
@@ -96,6 +98,9 @@ export async function POST(request: Request) {
9698
session,
9799
dataStream,
98100
}),
101+
web_search_preview: openai.tools.webSearchPreview({
102+
searchContextSize: 'medium'
103+
})
99104
},
100105
onFinish: async ({ response, reasoning }) => {
101106
if (session.user?.id) {
@@ -134,7 +139,7 @@ export async function POST(request: Request) {
134139
});
135140
},
136141
onError: () => {
137-
return 'Oops, an error occured!';
142+
return 'Oops, an error occurred!';
138143
},
139144
});
140145
} catch (error) {

0 commit comments

Comments
 (0)