Update app.py
Browse files
app.py
CHANGED
@@ -137,21 +137,30 @@ class BasicAgent:
|
|
137 |
|
138 |
# ---- Low‑level LLM call
|
139 |
def _call_llm(self, prompt: str, max_tokens: int = 256) -> str:
|
140 |
-
try
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
# ---- Workflow nodes
|
157 |
def _analyze_question(self, state: AgentState) -> AgentState:
|
|
|
137 |
|
138 |
# ---- Low‑level LLM call
|
139 |
def _call_llm(self, prompt: str, max_tokens: int = 256) -> str:
|
140 |
+
# List of models to try in order
|
141 |
+
models = ["gpt-4o-mini", "gpt-3.5-turbo", "gpt-4"]
|
142 |
+
|
143 |
+
for model in models:
|
144 |
+
try:
|
145 |
+
print(f"\nTrying model: {model}")
|
146 |
+
resp = self.llm.chat.completions.create(
|
147 |
+
model=model,
|
148 |
+
messages=[
|
149 |
+
{"role": "system", "content": "You are a careful reasoning assistant."},
|
150 |
+
{"role": "user", "content": prompt},
|
151 |
+
],
|
152 |
+
temperature=0.3,
|
153 |
+
max_tokens=max_tokens,
|
154 |
+
)
|
155 |
+
return resp.choices[0].message.content.strip()
|
156 |
+
except Exception as e:
|
157 |
+
print(f"Error with {model}: {str(e)}")
|
158 |
+
if model == models[-1]: # If this was the last model
|
159 |
+
print(f"All models failed. Last error: {str(e)}")
|
160 |
+
print(f"Prompt that caused error:\n{prompt}")
|
161 |
+
raise
|
162 |
+
print(f"Falling back to next model...")
|
163 |
+
continue
|
164 |
|
165 |
# ---- Workflow nodes
|
166 |
def _analyze_question(self, state: AgentState) -> AgentState:
|