Skip to content

Commit

Permalink
Merge pull request #198 from JasonRD/fix-ollama-json-output
Browse files Browse the repository at this point in the history
fix ollama output without json format
  • Loading branch information
huangyz0918 authored Sep 9, 2024
2 parents 8109d8b + 2e5a710 commit 50bca75
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mle/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ def query(self, chat_history, **kwargs):
Args:
chat_history: The context (chat history).
"""
return self.client.chat(model=self.model, messages=chat_history)['message']['content']

# Check if 'response_format' exists in kwargs
format = None
if 'response_format' in kwargs and kwargs['response_format'].get('type') == 'json_object':
format = 'json'

return self.client.chat(model=self.model, messages=chat_history, format=format)['message']['content']

def stream(self, chat_history, **kwargs):
"""
Expand Down

0 comments on commit 50bca75

Please sign in to comment.