Hamdy Doma commited on
Commit
4e33222
·
1 Parent(s): 3e05617

Fix AttributeError in system instruction injection

Browse files
Files changed (1) hide show
  1. api/routes.py +9 -5
api/routes.py CHANGED
@@ -90,11 +90,15 @@ async def create_message(
90
 
91
  # --- LANGUAGE MATCHING FIX ---
92
  # Add a system-level hint to ensure the AI responds in the user's language
93
- language_hint = {
94
- "role": "system",
95
- "content": "You must always respond in the same language as the user's last message. If the user speaks Arabic, reply in Arabic. If they speak English, reply in English."
96
- }
97
- request_data.messages.insert(0, language_hint)
 
 
 
 
98
 
99
  # Resolve provider from the model-aware mapping
100
  provider_type = Settings.parse_provider_type(
 
90
 
91
  # --- LANGUAGE MATCHING FIX ---
92
  # Add a system-level hint to ensure the AI responds in the user's language
93
+ lang_instruction = "You must always respond in the same language as the user's last message. If the user speaks Arabic, reply in Arabic. If they speak English, reply in English."
94
+
95
+ if not request_data.system:
96
+ request_data.system = lang_instruction
97
+ elif isinstance(request_data.system, str):
98
+ request_data.system = f"{lang_instruction}\n\n{request_data.system}"
99
+ elif isinstance(request_data.system, list):
100
+ from .models.anthropic import SystemContent
101
+ request_data.system.insert(0, SystemContent(type="text", text=lang_instruction))
102
 
103
  # Resolve provider from the model-aware mapping
104
  provider_type = Settings.parse_provider_type(