-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathopenai-web-search.ts
More file actions
38 lines (33 loc) · 1.01 KB
/
openai-web-search.ts
File metadata and controls
38 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { AxAIOpenAIModel, ai, ax } from '@ax-llm/ax';
export const webSearchGen = ax(
'userQuestion:string "User question to answer using live web search" -> answerText:string "Direct answer text", sourceCitations:json "Provider citations/URLs if available"'
);
console.log('=== OpenAI Web Search Demo ===');
const llm = ai({
name: 'openai',
apiKey: process.env.OPENAI_APIKEY!,
config: {
model: AxAIOpenAIModel.GPT5Mini,
stream: false,
webSearchOptions: {
searchContextSize: 'medium',
userLocation: {
approximate: {
type: 'approximate',
city: 'San Francisco',
region: 'California',
country: 'US',
timezone: 'America/Los_Angeles',
},
},
},
},
});
const result = await webSearchGen.forward(llm, {
userQuestion:
'What are the latest developments in fusion energy research this week?',
});
console.log(result.answerText);
if (result.sourceCitations) {
console.log(JSON.stringify(result.sourceCitations, null, 2));
}