naman1102 commited on
Commit
20becd7
·
1 Parent(s): 096d42a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -15
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
- resp = self.llm.chat.completions.create(
142
- model="gpt-4o-mini",
143
- messages=[
144
- {"role": "system", "content": "You are a careful reasoning assistant."},
145
- {"role": "user", "content": prompt},
146
- ],
147
- temperature=0.3,
148
- max_tokens=max_tokens,
149
- )
150
- return resp.choices[0].message.content.strip()
151
- except Exception as e:
152
- print(f"\nLLM Error: {str(e)}")
153
- print(f"Prompt that caused error:\n{prompt}")
154
- raise
 
 
 
 
 
 
 
 
 
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: