Bruce MacDonald 1 gadu atpakaļ
vecāks
revīzija
2fcbd63e81

+ 1 - 1
README.md

@@ -27,7 +27,7 @@ Response streaming can be enabled by setting `stream: true`, modifying function
 import ollama from 'ollama'
 
 const message = { role: 'user', content: 'Why is the sky blue?' }
-const { response } = await ollama.chat({ model: 'llama2', messages: [message], stream: true })
+const response = await ollama.chat({ model: 'llama2', messages: [message], stream: true })
 for await (const part of response) {
   process.stdout.write(part.message.content)
 }

+ 20 - 0
examples/fill-in-middle/fill.ts

@@ -0,0 +1,20 @@
+import ollama from 'ollama'
+
+const prefix = `def remove_non_ascii(s: str) -> str:
+"""
+`
+const suffix = `
+return result
+`
+const response = await ollama.generate({
+  model: 'codellama:7b-code',
+  prompt: `<PRE> ${prefix} <SUF>${suffix} <MID>`,
+  options: {
+    num_predict: 128,
+    temperature: 0,
+    top_p: 0.9,
+    presence_penalty: 0,
+    stop: ['<EOT>'],
+  },
+})
+console.log(response.response)

BIN
examples/multimodal/cat.jpg


+ 13 - 0
examples/multimodal/multimodal.ts

@@ -0,0 +1,13 @@
+import https from 'https'
+import ollama from 'ollama'
+
+const imagePath = './examples/multimodal/cat.jpg'
+const response = await ollama.generate({
+  model: 'llava',
+  prompt: 'describe this image:',
+  images: [imagePath],
+  stream: true,
+})
+for await (const part of response) {
+  process.stdout.write(part.response)
+}

+ 25 - 0
examples/pull-progress/pull.ts

@@ -0,0 +1,25 @@
+import ollama from 'ollama'
+
+const model = 'llama2'
+console.log(`downloading ${model}...`)
+let currentDigestDone = false
+const stream = await ollama.pull({ model: model, stream: true })
+for await (const part of stream) {
+  if (part.digest) {
+    let percent = 0
+    if (part.completed && part.total) {
+      percent = Math.round((part.completed / part.total) * 100)
+    }
+    process.stdout.clearLine(0) // Clear the current line
+    process.stdout.cursorTo(0) // Move cursor to the beginning of the line
+    process.stdout.write(`${part.status} ${percent}%...`) // Write the new text
+    if (percent === 100 && !currentDigestDone) {
+      console.log() // Output to a new line
+      currentDigestDone = true
+    } else {
+      currentDigestDone = false
+    }
+  } else {
+    console.log(part.status)
+  }
+}