mirror of
https://github.com/hwchase17/langchain.git
synced 2026-07-01 14:47:02 +00:00
`ChatMistralAI` now supports `stop` sequences. Previously, a `stop` value passed to the model was silently discarded: the code carried a stale "not yet supported" note, dropped the parameter before the request, and logged a warning. Mistral's chat completions API does accept `stop` (a string or list of strings, up to 4 sequences), so anyone setting `stop` and expecting generation to halt was getting no effect. Now `stop` is a first-class parameter. It can be set on the constructor (`ChatMistralAI(stop=[...])`) or per call (`model.invoke(prompt, stop=[...])`) and is forwarded to the API. A per-call value overrides the instance default, and an empty list is treated as "no stop sequences" — omitted from the request rather than sent as an empty array (which the API rejects). Verified against the live Mistral API: with `stop=["5"]`, "Count from 1 to 10" returns `1 2 3 4 ` instead of the full sequence. The 422 `extra_forbidden` response the API returns for genuinely unknown fields confirms `stop` is a real schema field, not silently ignored. This PR also folds in some test hygiene: the base-URL env test uses `monkeypatch.setenv` so `MISTRAL_BASE_URL=boo` no longer leaks into later serialization tests, and `test_extra_kwargs` asserts the intentional unknown-kwarg warning with `pytest.warns`. ## Review notes - Behavior change worth a careful look: `stop` now reaches the API instead of being dropped. This changes request payloads for anyone previously passing `stop`. It is the intended fix, but flagging it explicitly. - Coverage: `test_stop_sequence` (integration) exercises the end-to-end behavior; unit tests cover parameter wiring, per-call-vs-instance precedence, and the empty-list case.
FAQ
Looking for an integration not listed here? Check out the integrations documentation and the note in the libs/ README about third-party maintained packages.
Integration docs
For full documentation, see the primary and API reference docs for integrations.