Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎞️ add json format to OllamaCommon class #13848

Closed
wants to merge 10 commits into from
7 changes: 7 additions & 0 deletions libs/langchain/langchain/llms/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class _OllamaCommon(BaseLanguageModel):
template: Optional[str] = None
"""full prompt or prompt template (overrides what is defined in the Modelfile)"""

format: Optional[str] = None
"""set format to 'json' to enable JSON output"""

@property
def _default_params(self) -> Dict[str, Any]:
"""Get the default parameters for calling Ollama."""
Expand All @@ -116,6 +119,7 @@ def _default_params(self) -> Dict[str, Any]:
},
"system": self.system,
"template": self.template,
"format": self.format,
}

@property
Expand All @@ -141,6 +145,9 @@ def _create_stream(
if "model" in kwargs:
params["model"] = kwargs["model"]

if "format" in kwargs:
params["format"] = kwargs["format"]

if "options" in kwargs:
params["options"] = kwargs["options"]
else:
Expand Down