Skip to content

Commit

Permalink
fix: a bug where ollama would not in json mode
Browse files Browse the repository at this point in the history
  • Loading branch information
provos committed Oct 29, 2024
1 parent 78bd17a commit 3c4cba4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/planai/llm_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def _cached_chat(
# some models can generate structured outputs
if self.support_structured_outputs and response_schema:
kwargs["response_schema"] = response_schema
elif self.support_json_mode:
kwargs["format"] = "json"

# ollama expects temperature to be passed as an option
options = {}
Expand Down
2 changes: 2 additions & 0 deletions src/planai/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def chat(self, messages: List[Dict[str, str]], **kwargs) -> Dict[str, Any]:

content = message.parsed
else:
if "format" in kwargs and kwargs["format"] == "json":
api_params["response_format"] = {"type": "json_object"}
response = self.client.chat.completions.create(**api_params)
content = response.choices[0].message.content

Expand Down

0 comments on commit 3c4cba4

Please sign in to comment.