-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
57 lines (48 loc) · 1.5 KB
/
Copy pathexample.js
File metadata and controls
57 lines (48 loc) · 1.5 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const { BrowserAIAgent } = require('./dist/BrowserAIAgent');
const { AIAgentConfig, BrowserConfig } = require('./dist/types');
async function main() {
// Configuration
const aiConfig = {
apiKey: process.env.OPENAI_API_KEY || 'your-api-key-here',
model: 'gpt-4',
maxTokens: 2000,
temperature: 0.7
};
const browserConfig = {
headless: false, // Set to true for headless mode
timeout: 30000,
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
viewport: {
width: 1920,
height: 1080
}
};
const agent = new BrowserAIAgent(aiConfig, browserConfig);
try {
console.log('🚀 Initializing Browser AI Agent...');
await agent.initialize();
console.log('🔍 Performing a web search...');
const results = await agent.searchAndExtract(
"software engineering jobs",
{
title: 'h3, h2, a',
url: 'a',
description: 'div, p, span'
}
);
console.log('✅ Search completed!');
console.log('Results:', JSON.stringify(results, null, 2));
} catch (error) {
console.error('❌ Error:', error.message);
} finally {
await agent.close();
console.log('👋 Browser AI Agent closed');
}
}
// Check if OpenAI API key is set
if (!process.env.OPENAI_API_KEY) {
console.log('⚠️ Please set your OPENAI_API_KEY environment variable');
console.log(' Example: export OPENAI_API_KEY=your-api-key-here');
process.exit(1);
}
main();