Spaces:
Sleeping
Sleeping
Cyber Catalyst Team commited on
Commit ·
fe85614
1
Parent(s): 173859b
feat: implement completions model fallback to Mistral Large 2 in forge_execute
Browse files- backend.py +23 -6
backend.py
CHANGED
|
@@ -1793,12 +1793,29 @@ async def forge_execute(req: ForgeExecuteRequest, authorization: str = Header(No
|
|
| 1793 |
|
| 1794 |
for round_num in range(MAX_TOOL_ROUNDS + 1):
|
| 1795 |
await rate_limiter.wait_for_nim()
|
| 1796 |
-
response =
|
| 1797 |
-
|
| 1798 |
-
|
| 1799 |
-
|
| 1800 |
-
|
| 1801 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1802 |
|
| 1803 |
msg = response.choices[0].message
|
| 1804 |
tool_calls_payload = None
|
|
|
|
| 1793 |
|
| 1794 |
for round_num in range(MAX_TOOL_ROUNDS + 1):
|
| 1795 |
await rate_limiter.wait_for_nim()
|
| 1796 |
+
response = None
|
| 1797 |
+
try:
|
| 1798 |
+
response = await nim_client.chat.completions.create(
|
| 1799 |
+
model=RECOMMENDED_MODEL,
|
| 1800 |
+
messages=final_messages,
|
| 1801 |
+
tools=TOOLS,
|
| 1802 |
+
tool_choice="auto"
|
| 1803 |
+
)
|
| 1804 |
+
except Exception as e:
|
| 1805 |
+
log_activity(f"[Forge Fallback] NIM completions failed: {e}. Retrying with Mistral Large...")
|
| 1806 |
+
try:
|
| 1807 |
+
if mistral_client:
|
| 1808 |
+
response = await mistral_client.chat.completions.create(
|
| 1809 |
+
model="mistral-large-latest",
|
| 1810 |
+
messages=final_messages,
|
| 1811 |
+
tools=TOOLS,
|
| 1812 |
+
tool_choice="auto"
|
| 1813 |
+
)
|
| 1814 |
+
else:
|
| 1815 |
+
raise Exception("Mistral client not initialized")
|
| 1816 |
+
except Exception as e2:
|
| 1817 |
+
log_activity(f"[Forge Fallback Error] Mistral completions failed too: {e2}")
|
| 1818 |
+
raise e2
|
| 1819 |
|
| 1820 |
msg = response.choices[0].message
|
| 1821 |
tool_calls_payload = None
|