pull.ts 909 B

1234567891011121314151617181920212223242526272829
  1. import ollama from 'ollama'
  2. async function main() {
  3. const model = 'llama3.1'
  4. console.log(`downloading ${model}...`)
  5. let currentDigestDone = false
  6. const stream = await ollama.pull({ model: model, stream: true })
  7. for await (const part of stream) {
  8. if (part.digest) {
  9. let percent = 0
  10. if (part.completed && part.total) {
  11. percent = Math.round((part.completed / part.total) * 100)
  12. }
  13. process.stdout.clearLine(0) // Clear the current line
  14. process.stdout.cursorTo(0) // Move cursor to the beginning of the line
  15. process.stdout.write(`${part.status} ${percent}%...`) // Write the new text
  16. if (percent === 100 && !currentDigestDone) {
  17. console.log() // Output to a new line
  18. currentDigestDone = true
  19. } else {
  20. currentDigestDone = false
  21. }
  22. } else {
  23. console.log(part.status)
  24. }
  25. }
  26. }
  27. main().catch(console.error)