Fix #948 ollamaclient: add scanner error checking in stream function for handling context cancellation
When using ollamaclient, if the application triggers a context cancel for some reason(i.e. handling user cancellation in case of chatbot), and the cancel signal propagates before making the HTTP call (146 line in ollamaclient.go), an error is returned correctly.
However, if the cancel signal propagates after the HTTP call and response.Body is closed, a nil pointer exception occurs at line 152 of ollamallm.go because the scanner loop is not entered and ollamaclient.ChatResponse is not created.
Therefore, while I considered pre-creating ollamaclient.ChatResponse in the oolamallm package, I decided that propagating the context.Canceled error would be a better approach.
Fixes https://github.com/tmc/langchaingo/issues/948
PR Checklist
- [x] Read the Contributing documentation.
- [x] Read the Code of conduct documentation.
- [x] Name your Pull Request title clearly, concisely, and prefixed with the name of the primarily affected package you changed according to Good commit messages (such as
memory: add interfaces for X, Yorutil: add whizzbang helpers). - [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g.
Fixes #123). - [x] Describes the source of new concepts.
- [x] References existing implementations as appropriate.
- [x] Contains test coverage for new functions.
- [x] Passes all
golangci-lintchecks.
this would fix this issue #948
@tmc can I get a review? 👀
@tmc it is a simple fix in a situation when context deadline triggers and then cause a segmentation fault on resp.Message.Content.