Skip to content

feat: accept an external AbortSignal in chat() and generate() - #288

Open
emmanuel-adu wants to merge 1 commit into
ollama:mainfrom
emmanuel-adu:fix/external-abort-signal
Open

feat: accept an external AbortSignal in chat() and generate()#288
emmanuel-adu wants to merge 1 commit into
ollama:mainfrom
emmanuel-adu:fix/external-abort-signal

Conversation

@emmanuel-adu

@emmanuel-adu emmanuel-adu commented Jul 30, 2026

Copy link
Copy Markdown

Fixes #274.

chat() and generate() now take an optional second { signal } argument, linked to the internal AbortController used for the request. Lets callers cancel a specific call immediately (e.g. tied to a component unmount) instead of only being able to abort all ongoing requests via client.abort(). Fully backward compatible - omitting it preserves the existing behavior and call shape exactly.

Verification: Added test/abort-signal.test.ts - a fetch stand-in that only resolves/rejects based on the AbortSignal it's given, so the tests exercise real cancellation, not just mocked call args. Confirmed these tests fail against the current code and pass with the fix. Full suite (39 tests) still passes, tsc --noEmit and npm run lint are clean.

Ran the pre-fix behavior (1 test, fails as expected) alongside the new tests against the fix (5 tests, all pass):

test dashboard: before-fix test failing, after-fix tests passing

Both methods now take an optional second { signal } argument, threaded
through processStreamableRequest to the internal AbortController. This
lets callers cancel a specific request immediately (e.g. tied to a
component unmount or their own timeout), instead of only being able to
abort all ongoing requests via client.abort().

Fully backward compatible: omitting the option preserves the exact prior
call signature and behavior.

Fixes ollama#274
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.

Allow passing external AbortSignal to chat and generate methods

1 participant