-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathollama.js
55 lines (48 loc) · 1.54 KB
/
ollama.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
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env node
import { useLmBackend, useLmExpert } from "@agent-smith/brain";
//import { useLmBackend } from "../packages/brain/dist/backend.js";
//import { useLmExpert } from "../packages/brain/dist/expert.js";
// run a local Ollama instance before running this example
const model = "llama3.1:latest";
const ctx = 8192;
const templateName = "llama3";
const prompt = "Give me a short list of the planets names in the solar system";
const backend = useLmBackend({
name: "ollama",
localLm: "ollama",
onToken: (t) => process.stdout.write(t),
});
const ex = useLmExpert({
name: "default",
backend: backend,
template: templateName,
model: { name: model, ctx: ctx },
});
async function main() {
// check if the backend is up
await ex.backend.probe();
// check expert status: unavailable, available (the model is not loaded), ready
ex.checkStatus();
const status = ex.state.get().status;
if (status == "ready") {
console.log("Ok, the agent's brain is on, let's make him think\n")
} else if (status == "available") {
console.warn(`Loading model ...`);
// load the model in Ollama
await ex.loadModel()
} else {
console.warn(`Unfortunatly the agent's brain is ${status}: please check the inference server`);
return
}
// let's think
const params = { temperature: 0.2, min_p: 0.05 };
const res = await ex.think(
prompt,
params,
);
console.log("\n\nDone");
console.log(res.stats);
}
(async () => {
await main();
})();