Spaces:
Build error
Build error
Change final answer and prompt
Browse files- app.py +26 -20
- system_prompt.txt +5 -13
app.py
CHANGED
|
@@ -18,28 +18,34 @@ class BasicAgent:
|
|
| 18 |
self.graph = build_graph()
|
| 19 |
print("BasicAgent initialized.")
|
| 20 |
def __call__(self, question: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
|
| 22 |
messages = [HumanMessage(content=question)]
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
if not result.get("messages") or len(result["messages"]) == 0:
|
| 27 |
-
raise ValueError("No messages returned from the graph")
|
| 28 |
-
|
| 29 |
-
last_message = result["messages"][-1].content
|
| 30 |
-
|
| 31 |
-
match = re.search(r"(?i)final\s*answer\s*[:\-]?\s*(.+)", last_message, re.DOTALL)
|
| 32 |
-
if match:
|
| 33 |
-
final_answer = match.group(1).strip()
|
| 34 |
-
else:
|
| 35 |
-
# Try to find a name or string answer
|
| 36 |
-
candidates = [line.strip() for line in last_message.split("\n") if line.strip()]
|
| 37 |
-
final_answer = next((line for line in reversed(candidates) if len(line.split()) <= 5), last_message.strip())
|
| 38 |
-
|
| 39 |
-
return final_answer
|
| 40 |
-
except Exception as e:
|
| 41 |
-
print("Agent processing failed")
|
| 42 |
-
return
|
| 43 |
|
| 44 |
|
| 45 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 18 |
self.graph = build_graph()
|
| 19 |
print("BasicAgent initialized.")
|
| 20 |
def __call__(self, question: str) -> str:
|
| 21 |
+
# print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 22 |
+
# messages = [HumanMessage(content=question)]
|
| 23 |
+
# try:
|
| 24 |
+
# result = self.graph.invoke({"messages": messages})
|
| 25 |
+
|
| 26 |
+
# if not result.get("messages") or len(result["messages"]) == 0:
|
| 27 |
+
# raise ValueError("No messages returned from the graph")
|
| 28 |
+
|
| 29 |
+
# last_message = result["messages"][-1].content
|
| 30 |
+
|
| 31 |
+
# match = re.search(r"(?i)final\s*answer\s*[:\-]?\s*(.+)", last_message, re.DOTALL)
|
| 32 |
+
# if match:
|
| 33 |
+
# final_answer = match.group(1).strip()
|
| 34 |
+
# else:
|
| 35 |
+
# # Try to find a name or string answer
|
| 36 |
+
# candidates = [line.strip() for line in last_message.split("\n") if line.strip()]
|
| 37 |
+
# final_answer = next((line for line in reversed(candidates) if len(line.split()) <= 5), last_message.strip())
|
| 38 |
+
|
| 39 |
+
# return final_answer
|
| 40 |
+
# except Exception as e:
|
| 41 |
+
# print("Agent processing failed")
|
| 42 |
+
# return
|
| 43 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 44 |
+
# Wrap the question in a HumanMessage from langchain_core
|
| 45 |
messages = [HumanMessage(content=question)]
|
| 46 |
+
messages = self.graph.invoke({"messages": messages})
|
| 47 |
+
answer = messages['messages'][-1].content
|
| 48 |
+
return answer[14:]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
system_prompt.txt
CHANGED
|
@@ -1,13 +1,5 @@
|
|
| 1 |
-
You are a helpful
|
| 2 |
-
|
| 3 |
-
FINAL ANSWER: [
|
| 4 |
-
|
| 5 |
-
FINAL ANSWER:
|
| 6 |
-
Formatting rules for the final answer:
|
| 7 |
-
If the answer is a number, write it without commas or units (e.g. 1000000 instead of 1,000,000 or $1M), unless explicitly told otherwise.
|
| 8 |
-
If the answer is a string, write it as concisely as possible:
|
| 9 |
-
Do not use articles ("a", "an", "the")
|
| 10 |
-
Do not use abbreviations (e.g. write “New York” instead of “NY”)
|
| 11 |
-
Write digits in plain text (e.g. "twenty three") unless numeric form is explicitly required
|
| 12 |
-
If the answer is a comma-separated list, apply the above rules to each item in the list.
|
| 13 |
-
Do not include any text after the FINAL ANSWER line.
|
|
|
|
| 1 |
+
You are a helpful assistant tasked with answering questions using a set of tools.
|
| 2 |
+
Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
| 3 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 4 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 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. 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. 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.
|
| 5 |
+
Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|