Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,12 +39,12 @@ class BasicAgent:
|
|
| 39 |
FINAL ANSWER: [YOUR FINAL ANSWER]"
|
| 40 |
"""
|
| 41 |
|
| 42 |
-
def __init__(self, model_name: str = "gpt-
|
| 43 |
"""
|
| 44 |
Initialize the BasicAgent with the specified LLM.
|
| 45 |
|
| 46 |
Args:
|
| 47 |
-
model_name: The name of the model to use (defaults to gpt-
|
| 48 |
api_key: OpenAI API key (defaults to environment variable)
|
| 49 |
"""
|
| 50 |
# Use the provided API key or fall back to the environment variable
|
|
@@ -144,34 +144,30 @@ class BasicAgent:
|
|
| 144 |
Reasoning:
|
| 145 |
{all_thoughts}
|
| 146 |
|
| 147 |
-
Format your
|
| 148 |
- For numbers: No commas in large numbers, no units unless explicitly requested.
|
| 149 |
- For strings: Minimal, no articles, no abbreviations.
|
| 150 |
- For lists: Comma-separated values.
|
| 151 |
- Use digits in words unless otherwise stated.
|
| 152 |
|
| 153 |
-
IMPORTANT: Your answer must be concise and
|
|
|
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
""")
|
| 158 |
]
|
| 159 |
|
| 160 |
try:
|
| 161 |
response = self.llm.invoke(prompt)
|
|
|
|
| 162 |
|
| 163 |
-
#
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
if len(parts) > 1:
|
| 170 |
-
return parts[1].strip()
|
| 171 |
-
else:
|
| 172 |
-
return "Error: Malformed answer format."
|
| 173 |
-
else:
|
| 174 |
-
return response.content.strip()
|
| 175 |
except Exception as e:
|
| 176 |
return f"Error formatting answer: {str(e)}"
|
| 177 |
|
|
@@ -215,17 +211,12 @@ class BasicAgent:
|
|
| 215 |
# Step 4: Format final answer
|
| 216 |
final_answer = self.format_answer(question, thoughts)
|
| 217 |
|
| 218 |
-
|
| 219 |
-
formatted_response = "You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:\nFINAL ANSWER: [YOUR FINAL ANSWER]\n\n"
|
| 220 |
-
formatted_response += "\n\n".join(thoughts)
|
| 221 |
-
formatted_response += f"\n\nFINAL ANSWER: {final_answer}"
|
| 222 |
-
|
| 223 |
-
print(f"Agent returning answer with final part: {final_answer}")
|
| 224 |
return final_answer
|
| 225 |
except Exception as e:
|
| 226 |
print(f"Error running agent workflow: {e}")
|
| 227 |
-
# Fallback response
|
| 228 |
-
return "
|
| 229 |
|
| 230 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 231 |
"""
|
|
|
|
| 39 |
FINAL ANSWER: [YOUR FINAL ANSWER]"
|
| 40 |
"""
|
| 41 |
|
| 42 |
+
def __init__(self, model_name: str = "gpt-4.1", api_key: str = None):
|
| 43 |
"""
|
| 44 |
Initialize the BasicAgent with the specified LLM.
|
| 45 |
|
| 46 |
Args:
|
| 47 |
+
model_name: The name of the model to use (defaults to gpt-4.1)
|
| 48 |
api_key: OpenAI API key (defaults to environment variable)
|
| 49 |
"""
|
| 50 |
# Use the provided API key or fall back to the environment variable
|
|
|
|
| 144 |
Reasoning:
|
| 145 |
{all_thoughts}
|
| 146 |
|
| 147 |
+
Format your answer following these strict rules:
|
| 148 |
- For numbers: No commas in large numbers, no units unless explicitly requested.
|
| 149 |
- For strings: Minimal, no articles, no abbreviations.
|
| 150 |
- For lists: Comma-separated values.
|
| 151 |
- Use digits in words unless otherwise stated.
|
| 152 |
|
| 153 |
+
IMPORTANT: Your answer must be concise, precise and EXACT. Do not include explanations.
|
| 154 |
+
Do not include a prefix like "FINAL ANSWER:" in your response. Just provide the exact answer.
|
| 155 |
|
| 156 |
+
For example, if the answer is "5", just respond with "5".
|
| 157 |
+
If the answer is "New York", just respond with "New York".
|
| 158 |
""")
|
| 159 |
]
|
| 160 |
|
| 161 |
try:
|
| 162 |
response = self.llm.invoke(prompt)
|
| 163 |
+
answer = response.content.strip()
|
| 164 |
|
| 165 |
+
# Remove any "FINAL ANSWER:" prefix if it exists
|
| 166 |
+
if "FINAL ANSWER:" in answer:
|
| 167 |
+
parts = answer.split("FINAL ANSWER:")
|
| 168 |
+
answer = parts[1].strip()
|
| 169 |
+
|
| 170 |
+
return answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
except Exception as e:
|
| 172 |
return f"Error formatting answer: {str(e)}"
|
| 173 |
|
|
|
|
| 211 |
# Step 4: Format final answer
|
| 212 |
final_answer = self.format_answer(question, thoughts)
|
| 213 |
|
| 214 |
+
print(f"Agent returning answer: {final_answer}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
return final_answer
|
| 216 |
except Exception as e:
|
| 217 |
print(f"Error running agent workflow: {e}")
|
| 218 |
+
# Fallback response - return just the error message without the prefix
|
| 219 |
+
return "Error"
|
| 220 |
|
| 221 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 222 |
"""
|