re-enable markdown formatting when chatting with o3

This commit is contained in:
sabaimran
2025-02-18 21:12:03 +05:30
parent 0016fe06c9
commit de550e5ca7

View File

@@ -185,6 +185,17 @@ def llm_thread(
model_kwargs.pop("response_format", None)
elif model_name.startswith("o3-"):
temperature = 1
# Get the first system message and add the string `Formatting re-enabled` to it. See https://platform.openai.com/docs/guides/reasoning-best-practices
if len(formatted_messages) > 0:
system_messages = [
(i, message) for i, message in enumerate(formatted_messages) if message["role"] == "system"
]
if len(system_messages) > 0:
first_system_message_index, first_system_message = system_messages[0]
formatted_messages[first_system_message_index][
"content"
] = f"{first_system_message} Formatting re-enabled"
elif model_name.startswith("deepseek-reasoner"):
# Two successive messages cannot be from the same role. Should merge any back-to-back messages from the same role.
# The first message should always be a user message (except system message).