Spaces:
Sleeping
Sleeping
Cyber Catalyst Team commited on
Commit ·
787cf39
1
Parent(s): 84929b9
feat: implement multi-provider model fallback to Mistral Large 2 in cycles
Browse files- backend.py +40 -4
backend.py
CHANGED
|
@@ -1970,20 +1970,38 @@ async def execute_build_cycle(project_name: str, goal: str):
|
|
| 1970 |
"Write ONE JSON instruction for Space 3 (The Forge) to code the next milestone. "
|
| 1971 |
"Respond ONLY with JSON: {\"prompt\": \"task description\", \"context_rules\": \"rules\"}"
|
| 1972 |
)
|
|
|
|
| 1973 |
try:
|
| 1974 |
res = await nim_client.chat.completions.create(
|
| 1975 |
-
model=
|
| 1976 |
messages=[{"role": "user", "content": plan_prompt}],
|
| 1977 |
max_tokens=300
|
| 1978 |
)
|
| 1979 |
raw = res.choices[0].message.content.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1980 |
if raw.startswith("```"):
|
| 1981 |
raw = raw.split("```")[1].lstrip("json").strip()
|
| 1982 |
task = json.loads(raw)
|
| 1983 |
task_prompt = task.get("prompt", "")
|
| 1984 |
context_rules = task.get("context_rules", "")
|
| 1985 |
except Exception as e:
|
| 1986 |
-
log_activity(f"[Build Mode Error]
|
| 1987 |
return
|
| 1988 |
|
| 1989 |
# Use the context-locked Bell Curve prompt builder (enforces max 2500 tokens)
|
|
@@ -2088,20 +2106,38 @@ async def execute_eternity_cycle(project_name: str, goal: str):
|
|
| 2088 |
"Based on this research, plan the SINGLE most impactful next feature to implement. "
|
| 2089 |
"Respond ONLY with JSON: {\"prompt\": \"task\", \"context_rules\": \"rules\"}"
|
| 2090 |
)
|
|
|
|
| 2091 |
try:
|
| 2092 |
res = await nim_client.chat.completions.create(
|
| 2093 |
-
model=
|
| 2094 |
messages=[{"role": "user", "content": plan_prompt}],
|
| 2095 |
max_tokens=300
|
| 2096 |
)
|
| 2097 |
raw = res.choices[0].message.content.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2098 |
if raw.startswith("```"):
|
| 2099 |
raw = raw.split("```")[1].lstrip("json").strip()
|
| 2100 |
task = json.loads(raw)
|
| 2101 |
task_prompt = task.get("prompt", "")
|
| 2102 |
context_rules = task.get("context_rules", "")
|
| 2103 |
except Exception as e:
|
| 2104 |
-
log_activity(f"[Eternity Mode Error]
|
| 2105 |
return
|
| 2106 |
|
| 2107 |
# Step 3: Build Karpathy context-locked prompt (Apex)
|
|
|
|
| 1970 |
"Write ONE JSON instruction for Space 3 (The Forge) to code the next milestone. "
|
| 1971 |
"Respond ONLY with JSON: {\"prompt\": \"task description\", \"context_rules\": \"rules\"}"
|
| 1972 |
)
|
| 1973 |
+
raw = ""
|
| 1974 |
try:
|
| 1975 |
res = await nim_client.chat.completions.create(
|
| 1976 |
+
model=RECOMMENDED_MODEL,
|
| 1977 |
messages=[{"role": "user", "content": plan_prompt}],
|
| 1978 |
max_tokens=300
|
| 1979 |
)
|
| 1980 |
raw = res.choices[0].message.content.strip()
|
| 1981 |
+
except Exception as e:
|
| 1982 |
+
log_activity(f"[Model Fallback] NIM failed ({e}). Retrying with Mistral Large...")
|
| 1983 |
+
try:
|
| 1984 |
+
if mistral_client:
|
| 1985 |
+
res = await mistral_client.chat.completions.create(
|
| 1986 |
+
model="mistralai/mistral-large-2-instruct",
|
| 1987 |
+
messages=[{"role": "user", "content": plan_prompt}],
|
| 1988 |
+
max_tokens=300
|
| 1989 |
+
)
|
| 1990 |
+
raw = res.choices[0].message.content.strip()
|
| 1991 |
+
else:
|
| 1992 |
+
raise Exception("Mistral client not initialized")
|
| 1993 |
+
except Exception as e2:
|
| 1994 |
+
log_activity(f"[Model Fallback Error] Mistral failed too: {e2}")
|
| 1995 |
+
return
|
| 1996 |
+
|
| 1997 |
+
try:
|
| 1998 |
if raw.startswith("```"):
|
| 1999 |
raw = raw.split("```")[1].lstrip("json").strip()
|
| 2000 |
task = json.loads(raw)
|
| 2001 |
task_prompt = task.get("prompt", "")
|
| 2002 |
context_rules = task.get("context_rules", "")
|
| 2003 |
except Exception as e:
|
| 2004 |
+
log_activity(f"[Build Mode Error] Plan JSON parsing failed: {e} | Raw: {raw}")
|
| 2005 |
return
|
| 2006 |
|
| 2007 |
# Use the context-locked Bell Curve prompt builder (enforces max 2500 tokens)
|
|
|
|
| 2106 |
"Based on this research, plan the SINGLE most impactful next feature to implement. "
|
| 2107 |
"Respond ONLY with JSON: {\"prompt\": \"task\", \"context_rules\": \"rules\"}"
|
| 2108 |
)
|
| 2109 |
+
raw = ""
|
| 2110 |
try:
|
| 2111 |
res = await nim_client.chat.completions.create(
|
| 2112 |
+
model=RECOMMENDED_MODEL,
|
| 2113 |
messages=[{"role": "user", "content": plan_prompt}],
|
| 2114 |
max_tokens=300
|
| 2115 |
)
|
| 2116 |
raw = res.choices[0].message.content.strip()
|
| 2117 |
+
except Exception as e:
|
| 2118 |
+
log_activity(f"[Model Fallback] NIM failed ({e}). Retrying with Mistral Large...")
|
| 2119 |
+
try:
|
| 2120 |
+
if mistral_client:
|
| 2121 |
+
res = await mistral_client.chat.completions.create(
|
| 2122 |
+
model="mistralai/mistral-large-2-instruct",
|
| 2123 |
+
messages=[{"role": "user", "content": plan_prompt}],
|
| 2124 |
+
max_tokens=300
|
| 2125 |
+
)
|
| 2126 |
+
raw = res.choices[0].message.content.strip()
|
| 2127 |
+
else:
|
| 2128 |
+
raise Exception("Mistral client not initialized")
|
| 2129 |
+
except Exception as e2:
|
| 2130 |
+
log_activity(f"[Model Fallback Error] Mistral failed too: {e2}")
|
| 2131 |
+
return
|
| 2132 |
+
|
| 2133 |
+
try:
|
| 2134 |
if raw.startswith("```"):
|
| 2135 |
raw = raw.split("```")[1].lstrip("json").strip()
|
| 2136 |
task = json.loads(raw)
|
| 2137 |
task_prompt = task.get("prompt", "")
|
| 2138 |
context_rules = task.get("context_rules", "")
|
| 2139 |
except Exception as e:
|
| 2140 |
+
log_activity(f"[Eternity Mode Error] Plan JSON parsing failed: {e} | Raw: {raw}")
|
| 2141 |
return
|
| 2142 |
|
| 2143 |
# Step 3: Build Karpathy context-locked prompt (Apex)
|