Python: Preserve reasoning blocks with OpenRouter (#2950)

* Preserve reasoning blocks with OpenRouter

* Put encrypted reasoning in TextReasoningContent

* Remove unneccessary change

* Fix docs

* Support streaming

* Fix handling None in TextReasoningContent.text
This commit is contained in:
SuperKenVery
2025-12-20 01:03:19 +08:00
committed by GitHub
Unverified
parent 6930c0f0b6
commit 85d70f01f6
4 changed files with 41 additions and 5 deletions
@@ -239,7 +239,8 @@ class OllamaChatClient(BaseChatClient):
def _format_assistant_message(self, message: ChatMessage) -> list[OllamaMessage]:
text_content = message.text
reasoning_contents = "".join(c.text for c in message.contents if isinstance(c, TextReasoningContent))
# Ollama shouldn't have encrypted reasoning, so we just process text.
reasoning_contents = "".join((c.text or "") for c in message.contents if isinstance(c, TextReasoningContent))
assistant_message = OllamaMessage(role="assistant", content=text_content, thinking=reasoning_contents)