Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -189,7 +189,7 @@ class BasicAgent:
|
|
| 189 |
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. \
|
| 190 |
If you are asked for a number, use only digits in your final answer. Don't use comma nor brackets to write your number neither use units such as $ or percent sign unless specified otherwise. \
|
| 191 |
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. \
|
| 192 |
-
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
|
| 193 |
If there is a file attached, open the file and read it. \
|
| 194 |
If you don't have enough references to answer, use your tools, search the web, run your code or convert data to a data frame, whatever helps. \
|
| 195 |
If the question refers to an external content and there is no reference file attached, perform a web search and retrieve relevant information from the internet. \
|
|
@@ -198,18 +198,21 @@ class BasicAgent:
|
|
| 198 |
)
|
| 199 |
message = HumanMessage(content=question)
|
| 200 |
print(message)
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
return answer
|
| 215 |
|
|
|
|
| 189 |
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. \
|
| 190 |
If you are asked for a number, use only digits in your final answer. Don't use comma nor brackets to write your number neither use units such as $ or percent sign unless specified otherwise. \
|
| 191 |
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. \
|
| 192 |
+
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.\
|
| 193 |
If there is a file attached, open the file and read it. \
|
| 194 |
If you don't have enough references to answer, use your tools, search the web, run your code or convert data to a data frame, whatever helps. \
|
| 195 |
If the question refers to an external content and there is no reference file attached, perform a web search and retrieve relevant information from the internet. \
|
|
|
|
| 198 |
)
|
| 199 |
message = HumanMessage(content=question)
|
| 200 |
print(message)
|
| 201 |
+
answer = None
|
| 202 |
+
while not answer:
|
| 203 |
+
try:
|
| 204 |
+
alfred = build_agent(chat1)
|
| 205 |
+
answer = alfred.invoke(input={"messages": [system_prompt, message]},config={"recursion_limit": 6})['messages'][-1].content
|
| 206 |
+
except Exception as e:
|
| 207 |
+
alfred = build_agent(chat2)
|
| 208 |
+
answer = alfred.invoke(input={"messages": [system_prompt, message]},config={"recursion_limit": 6})['messages'][-1].content
|
| 209 |
+
if answer:
|
| 210 |
+
answer = "".join(re.findall(r'(FINAL ANSWER.*)', answer, flags=re.M))
|
| 211 |
+
answer = answer.replace('FINAL ANSWER:', '')
|
| 212 |
+
answer = answer.replace('FINAL ANSWER', '')
|
| 213 |
+
answer = answer.replace('YOUR ', '')
|
| 214 |
+
answer = answer.replace('*', '')
|
| 215 |
+
print(f"Agent returning fixed answer: {answer}")
|
| 216 |
|
| 217 |
return answer
|
| 218 |
|