Skip to content

Conversation

bariscelik
Copy link

@bariscelik bariscelik commented Sep 24, 2024

Abort signal was working only for ReadableStream after a request was sent. Now, it works even at the beginning of the request.

This could be integrated better but I didn't want to refactor the AbortableAsyncIterator structure.

Copy link

@GerkinDev GerkinDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be very much appreciated, but IMO the public interfaces should use AbortSignal instead.

console.log('\nAborting request...\n')
ollama.abort()
}, 1000) // 1000 milliseconds = 1 second
}, 500) // 1000 milliseconds = 1 second

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not needed


export interface GenerateRequest {
interface AbortableRequest {
abortController?: AbortController
Copy link

@GerkinDev GerkinDev Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what I've seen, consummers are generally taking an AbortSignal named signal, and not an AbortController. The user can provide it through new AbortController().signal, AbortSignal.timeout() or any other producer. See for example https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#signal

const itr = parseJSON<T | ErrorResponse>(response.body)
const abortableAsyncIterator = new AbortableAsyncIterator(
abortController,
request.abortController ?? abortController,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If taking an AbortSignal as suggested in src/interfaces.ts, you could instead call abortController.abort() when the signal emits to propagate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants