Skip to content

Commit 837ca47

Browse files
committed
feat(agents): Add ollama:pull script
1 parent 11ecc74 commit 837ca47

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

packages/agents/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"lint:eslint": "eslint . --cache",
3939
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies",
4040
"lint:misc": "prettier --no-error-on-unmatched-pattern '**/*.json' '**/*.md' '**/*.html' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path ../../.gitignore",
41+
"ollama:pull": "node scripts/ollama-pull.js",
4142
"publish:preview": "yarn npm publish --tag preview",
4243
"test": "vitest run --config vitest.config.ts",
4344
"test:clean": "yarn test --no-cache --coverage.clean",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Ollama } from 'ollama';
2+
3+
main().catch(console.error);
4+
5+
/**
6+
* The main function for the script.
7+
*/
8+
async function main() {
9+
// Make a new ollama client.
10+
const ollama = new Ollama({ host: 'http://localhost:11434' });
11+
12+
let nDots = 0;
13+
const interval = setInterval(() => (nDots = (nDots + 1) % 4), 250);
14+
try {
15+
const model = process.argv[2];
16+
const labelDuring = `Pulling ${model}`;
17+
const labelAfter = `Pulled ${model}`;
18+
const makeProgress = (fraction) =>
19+
[
20+
labelDuring,
21+
`${'.'.repeat(nDots)}${' '.repeat(4 - nDots)}`,
22+
'[',
23+
`${'='.repeat(Math.floor(fraction * 10))}`,
24+
`${' '.repeat(10 - Math.floor(fraction * 10))}`,
25+
']',
26+
` ${Math.floor(fraction * 100)}%`,
27+
].join('');
28+
const result = await ollama.pull({ model, stream: true });
29+
for await (const chunk of result) {
30+
process.stdout.write(`${makeProgress(chunk.completed / chunk.total)}\r`);
31+
}
32+
console.log(
33+
`${labelAfter} ${' '.repeat(15 + labelDuring.length - labelAfter.length)}`,
34+
);
35+
} finally {
36+
clearInterval(interval);
37+
}
38+
}

0 commit comments

Comments
 (0)