-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathllm-extraction.ts
More file actions
42 lines (37 loc) · 1.36 KB
/
Copy pathllm-extraction.ts
File metadata and controls
42 lines (37 loc) · 1.36 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
/**
* Describe what you want in plain English and let Maxun build the robot.
*
* On Maxun Cloud nothing else is needed. On self-hosted Maxun an LLM is
* required: set MAXUN_LLM_PROVIDER (anthropic, openai or ollama) and, for
* anthropic/openai, MAXUN_LLM_API_KEY. They are passed through only when set.
*/
import 'dotenv/config';
import { Maxun, LlmOptions } from 'maxun-sdk';
const maxun = new Maxun();
const llm: LlmOptions = Object.fromEntries(
Object.entries({
llmProvider: process.env.MAXUN_LLM_PROVIDER,
llmModel: process.env.MAXUN_LLM_MODEL,
llmApiKey: process.env.MAXUN_LLM_API_KEY,
llmBaseUrl: process.env.MAXUN_LLM_BASE_URL,
}).filter(([, value]) => value)
);
async function main() {
// With a URL
const robot = await maxun.extract('YC Companies', 'https://www.ycombinator.com/companies', {
prompt: 'Extract the first 15 company names, descriptions and batch',
...llm,
});
const result = await robot.run();
console.log(JSON.stringify(result.listData.slice(0, 3), null, 2));
// Without a URL, Maxun searches for a suitable page first
const auto = await maxun.extract('YC Companies (auto-search)', {
prompt: 'Company names and descriptions from the Y Combinator companies directory',
...llm,
});
console.log(`Robot built for ${auto.url}`);
}
main().catch((error) => {
console.error(error);
process.exit(1);
});