Skip to content

Commit

Permalink
Fixed catch in abort examples (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
hopperelec authored Aug 6, 2024
1 parent f73dae5 commit 8607c28
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions examples/abort/any-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ setTimeout(() => {
ollama.abort()
}, 1000) // 1000 milliseconds = 1 second

try {
ollama.generate({
ollama.generate({
model: 'llama3.1',
prompt: 'Write a long story',
stream: true,
Expand All @@ -17,11 +16,12 @@ try {
process.stdout.write(chunk.response)
}
}
).catch(
(error) => {
if (error.name === 'AbortError') {
console.log('The request has been aborted')
} else {
console.error('An error occurred:', error)
}
}
)
} catch (error) {
if (error.name === 'AbortError') {
console.log('The request has been aborted')
} else {
console.error('An error occurred:', error)
}
}
18 changes: 9 additions & 9 deletions examples/abort/specific-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ setTimeout(() => {
stream.abort()
}, 1000) // 1000 milliseconds = 1 second

try {
ollama.generate({
ollama.generate({
model: 'llama3.1',
prompt: 'Write a long story',
stream: true,
Expand All @@ -21,11 +20,12 @@ try {
process.stdout.write(chunk.response)
}
}
).catch(
(error) => {
if (error.name === 'AbortError') {
console.log('The request has been aborted')
} else {
console.error('An error occurred:', error)
}
}
)
} catch (error) {
if (error.name === 'AbortError') {
console.log('The request has been aborted')
} else {
console.error('An error occurred:', error)
}
}

0 comments on commit 8607c28

Please sign in to comment.