pull.ts 808 B

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