Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,7 +64,7 @@ agent = initialize_agent(
|
|
| 64 |
agent_kwargs={
|
| 65 |
"system_message": SystemMessage(content="You are a general AI assistant. I will ask you a question. "
|
| 66 |
"Report your thoughts, and finish your answer with the following template: "
|
| 67 |
-
"[YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. "
|
| 68 |
"If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. "
|
| 69 |
"If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. "
|
| 70 |
"If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.")
|
|
@@ -77,8 +77,19 @@ class BasicAgent:
|
|
| 77 |
self.agent = agent
|
| 78 |
|
| 79 |
def __call__(self, question: str) -> str:
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
|
| 84 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 64 |
agent_kwargs={
|
| 65 |
"system_message": SystemMessage(content="You are a general AI assistant. I will ask you a question. "
|
| 66 |
"Report your thoughts, and finish your answer with the following template: "
|
| 67 |
+
"FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. "
|
| 68 |
"If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. "
|
| 69 |
"If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. "
|
| 70 |
"If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.")
|
|
|
|
| 77 |
self.agent = agent
|
| 78 |
|
| 79 |
def __call__(self, question: str) -> str:
|
| 80 |
+
|
| 81 |
+
def extract_model_answer(full_response: str) -> str:
|
| 82 |
+
marker = "FINAL ANSWER:"
|
| 83 |
+
idx = full_response.find(marker)
|
| 84 |
+
if idx == -1:
|
| 85 |
+
return full_response.strip() # fallback: return whole response
|
| 86 |
+
return full_response[idx + len(marker):].strip().rstrip(".")
|
| 87 |
+
|
| 88 |
+
response = self.agent.run(question)
|
| 89 |
+
model_answer = response["messages"][-1].content
|
| 90 |
+
fixed_answer = extract_model_answer(model_answer)
|
| 91 |
+
reasoning_trace = "\n".join([f"{m.type}: {m.content}" for m in messages + response["messages"]])
|
| 92 |
+
return fixed_answer
|
| 93 |
|
| 94 |
|
| 95 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|