Skip to content

Commit

Permalink
community[patch]: Added support for Ollama's num_predict option in Ch…
Browse files Browse the repository at this point in the history
…atOllama (#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: #14715
  • Loading branch information
micahparker authored Jan 26, 2024
1 parent 6a75ef7 commit 6543e58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libs/community/langchain_community/llms/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"""
Expand Down Expand Up @@ -126,6 +130,7 @@ def _default_params(self) -> Dict[str, Any]:
"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,
Expand Down
2 changes: 2 additions & 0 deletions libs/community/tests/unit_tests/llms/test_ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def mock_post(url, headers, json, stream, timeout):
"num_ctx": None,
"num_gpu": None,
"num_thread": None,
"num_predict": None,
"repeat_last_n": None,
"repeat_penalty": None,
"stop": [],
Expand Down Expand Up @@ -133,6 +134,7 @@ def mock_post(url, headers, json, stream, timeout):
"num_ctx": None,
"num_gpu": None,
"num_thread": None,
"num_predict": None,
"repeat_last_n": None,
"repeat_penalty": None,
"stop": [],
Expand Down

0 comments on commit 6543e58

Please sign in to comment.