File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments