community[patch]: Added support for Ollama's num_predict option in ChatOllama (#16633)

Just a simple default addition to the options payload for a ollama
generate call to support a max_new_tokens parameter.

Should fix issue: https://github.com/langchain-ai/langchain/issues/14715
pull/16657/head
Micah Parker 8 months ago committed by GitHub
parent 6a75ef74ca
commit 6543e585a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -64,6 +64,10 @@ class _OllamaCommon(BaseLanguageModel):
It is recommended to set this value to the number of physical
CPU cores your system has (as opposed to the logical number of cores)."""
num_predict: Optional[int] = None
"""Maximum number of tokens to predict when generating text.
(Default: 128, -1 = infinite generation, -2 = fill context)"""
repeat_last_n: Optional[int] = None
"""Sets how far back for the model to look back to prevent
repetition. (Default: 64, 0 = disabled, -1 = num_ctx)"""
@ -126,6 +130,7 @@ class _OllamaCommon(BaseLanguageModel):
"num_ctx": self.num_ctx,
"num_gpu": self.num_gpu,
"num_thread": self.num_thread,
"num_predict": self.num_predict,
"repeat_last_n": self.repeat_last_n,
"repeat_penalty": self.repeat_penalty,
"temperature": self.temperature,

@ -88,6 +88,7 @@ def test_handle_kwargs_top_level_parameters(monkeypatch: MonkeyPatch) -> None:
"num_ctx": None,
"num_gpu": None,
"num_thread": None,
"num_predict": None,
"repeat_last_n": None,
"repeat_penalty": None,
"stop": [],
@ -133,6 +134,7 @@ def test_handle_kwargs_with_unknown_param(monkeypatch: MonkeyPatch) -> None:
"num_ctx": None,
"num_gpu": None,
"num_thread": None,
"num_predict": None,
"repeat_last_n": None,
"repeat_penalty": None,
"stop": [],

Loading…
Cancel
Save