feat: accept an external AbortSignal in chat() and generate() - #288
Open
emmanuel-adu wants to merge 1 commit into
Open
feat: accept an external AbortSignal in chat() and generate()#288emmanuel-adu wants to merge 1 commit into
emmanuel-adu wants to merge 1 commit into
Conversation
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
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.
Fixes #274.
chat()andgenerate()now take an optional second{ signal }argument, linked to the internalAbortControllerused 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 viaclient.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 --noEmitandnpm run lintare clean.Ran the pre-fix behavior (1 test, fails as expected) alongside the new tests against the fix (5 tests, all pass):