-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathllm-extraction.ts
More file actions
94 lines (75 loc) · 2.98 KB
/
Copy pathllm-extraction.ts
File metadata and controls
94 lines (75 loc) · 2.98 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* LLM-based Extraction Example
*
* This example demonstrates:
* - Using natural language prompts to extract data
* - LLM automatically generates the extraction workflow
* - Support for multiple LLM providers (Ollama, Anthropic, OpenAI)
* - Creates a reusable robot that can be executed anytime
* - Auto-search: When no URL is provided, the system searches for the website automatically
*
* Site: Y Combinator Companies (https://www.ycombinator.com/companies)
*/
import 'dotenv/config';
import { Extract } from 'maxun-sdk';
async function main() {
const extractor = new Extract({
apiKey: process.env.MAXUN_API_KEY!,
baseUrl: process.env.MAXUN_BASE_URL!
});
try {
console.log('Example 1: Creating robot with configured URL...\n');
const robot = await extractor.extract({
url: 'https://www.ycombinator.com/companies',
prompt: 'Extract the first 15 YC company names, their descriptions, and batch information',
llmProvider: 'ollama',
llmModel: 'llama3.2-vision',
llmBaseUrl: 'http://localhost:11434',
robotName: 'YC Companies LLM Extractor'
});
console.log(`Robot created: ${robot.id}`);
// Execute the generated robot
console.log('Executing robot...\n');
const result = await robot.run();
console.log(`Extraction completed!`);
console.log(` Status: ${result.status}`);
console.log(` Companies extracted: ${result.data.listData?.length || 0}\n`);
console.log('First 3 companies:');
console.log(JSON.stringify(result.data.listData?.slice(0, 3), null, 2));
console.log('\n\nExample 2: Creating robot without configured URL...\n');
const autoSearchRobot = await extractor.extract({
prompt: 'Extract company names and descriptions from the YCombinator Companies page',
llmProvider: 'ollama',
robotName: 'YC Auto-Search Extractor'
});
console.log(`Auto-search robot created: ${autoSearchRobot.id}`);
// Execute the generated robot
console.log('Executing robot...\n');
const autoSearchResult = await autoSearchRobot.run();
console.log(`Extraction completed!`);
console.log(` Status: ${autoSearchResult.status}`);
console.log(` Companies extracted: ${autoSearchResult.data.listData?.length || 0}\n`);
console.log('First 3 companies:');
console.log(JSON.stringify(autoSearchResult.data.listData?.slice(0, 3), null, 2));
// Note: For Anthropic (recommended for best results):
// llmProvider: 'anthropic',
// llmModel: 'claude-3-5-sonnet-20241022',
// llmApiKey: process.env.ANTHROPIC_API_KEY
//
// For OpenAI:
// llmProvider: 'openai',
// llmModel: 'gpt-4-vision-preview',
// llmApiKey: process.env.OPENAI_API_KEY
} catch (error: any) {
console.error('Error:', error.message);
if (error.details) {
console.error('Details:', error.details);
}
process.exit(1);
}
}
if (!process.env.MAXUN_API_KEY) {
console.error('Error: MAXUN_API_KEY environment variable is required');
process.exit(1);
}
main();