Add custom abort controller for requests#146
Open
bariscelik wants to merge 2 commits intoollama:mainfrom
Open
Conversation
GerkinDev
reviewed
Jul 10, 2025
GerkinDev
left a comment
There was a problem hiding this comment.
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 |
|
|
||
| export interface GenerateRequest { | ||
| interface AbortableRequest { | ||
| abortController?: AbortController |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
If taking an AbortSignal as suggested in src/interfaces.ts, you could instead call abortController.abort() when the signal emits to propagate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.