AUXteam commited on
Commit
8e7cffc
·
verified ·
1 Parent(s): 10e7104

Fix: combine system messages to satisfy strict LLM chatml parser

Browse files
Files changed (1) hide show
  1. tinytroupe/openai_utils.py +7 -1
tinytroupe/openai_utils.py CHANGED
@@ -226,10 +226,16 @@ class OpenAIClient:
226
  def _raw_model_call(self, model, chat_api_params):
227
 
228
  # Ensure system message is strictly first
 
229
  if "messages" in chat_api_params:
230
  system_msgs = [m for m in chat_api_params["messages"] if m.get("role") == "system"]
231
  other_msgs = [m for m in chat_api_params["messages"] if m.get("role") != "system"]
232
- chat_api_params["messages"] = system_msgs + other_msgs
 
 
 
 
 
233
 
234
 
235
  """
 
226
  def _raw_model_call(self, model, chat_api_params):
227
 
228
  # Ensure system message is strictly first
229
+
230
  if "messages" in chat_api_params:
231
  system_msgs = [m for m in chat_api_params["messages"] if m.get("role") == "system"]
232
  other_msgs = [m for m in chat_api_params["messages"] if m.get("role") != "system"]
233
+
234
+ # Combine all system messages into one single system message block to satisfy strict ChatML
235
+ if system_msgs:
236
+ combined_content = "\n\n".join([m.get("content", "") for m in system_msgs])
237
+ chat_api_params["messages"] = [{"role": "system", "content": combined_content}] + other_msgs
238
+
239
 
240
 
241
  """