Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix top await in examples #206

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions examples/fill-in-middle/fill.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import ollama from 'ollama'

const response = await ollama.generate({
model: 'deepseek-coder-v2',
prompt: `def add(`,
suffix: `return c`,
})
console.log(response.response)
async function main() {
const response = await ollama.generate({
model: 'deepseek-coder-v2',
prompt: `def add(`,
suffix: `return c`,
})
console.log(response.response)
}

main().catch(console.error)
22 changes: 13 additions & 9 deletions examples/multimodal/multimodal.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
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)
async function main() {
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)
}
}

main().catch(console.error)
42 changes: 23 additions & 19 deletions examples/pull-progress/pull.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import ollama from 'ollama'

const model = 'llama3.1'
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
async function main() {
const model = 'llama3.1'
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 {
currentDigestDone = false
console.log(part.status)
}
} else {
console.log(part.status)
}
}

main().catch(console.error)