Skip to content

Add custom abort controller for requests#146

Open
bariscelik wants to merge 2 commits intoollama:mainfrom
bariscelik:custom-abort-controller
Open

Add custom abort controller for requests#146
bariscelik wants to merge 2 commits intoollama:mainfrom
bariscelik:custom-abort-controller

Conversation

@bariscelik
Copy link
Copy Markdown

@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
Copy Markdown

@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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe not needed

Comment thread src/interfaces.ts

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

@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

Comment thread src/browser.ts
const itr = parseJSON<T | ErrorResponse>(response.body)
const abortableAsyncIterator = new AbortableAsyncIterator(
abortController,
request.abortController ?? abortController,
Copy link
Copy Markdown

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