-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlmtask.js
45 lines (40 loc) · 1.37 KB
/
lmtask.js
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
#!/usr/bin/env node
//import { useLmTask } from "@agent-smith/lmtask";
import { default as fs } from "fs";
import { useAgentBrain } from "@agent-smith/brain";
import { LmTaskBuilder } from "@agent-smith/lmtask";
//import { useAgentBrain } from "../packages/brain/dist/brain.js";
//import { LmTaskBuilder } from "../packages/lmtask/dist/task.js"
// Run an Ollama server
const model = "llama3.1:latest";
const template = "llama3";
async function main() {
const taskPath = "./sample/mytask.yml"
const brain = useAgentBrain();
await brain.initLocal();
brain.backend("ollama").setOnToken((t) => process.stdout.write(t));
const ex = brain.getOrCreateExpertForModel(model, template);
if (!ex) {
console.error("No backend found for model")
}
const ymlTaskDef = fs.readFileSync(taskPath, 'utf8');
const taskBuilder = new LmTaskBuilder(brain);
// build the task
const task = taskBuilder.fromYaml(ymlTaskDef);
console.log("Running task...", ymlTaskDef);
// run the task
const conf = {
expert: ex,
model: model,
template: template,
debug: true,
};
await task.run({
prompt: "What are your favourite activities?",
name: "Mr Brown", role: "marketing director",
instructions: "Important: answer with a markdown bullet points list"
}, conf);
}
(async () => {
await main();
})();