Fix errors + set recursion limit to be 10
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ from langgraph.prebuilt import ToolNode, tools_condition
|
|
| 23 |
|
| 24 |
from langchain_openai import ChatOpenAI
|
| 25 |
from langchain_core.messages import SystemMessage, HumanMessage, AnyMessage
|
|
|
|
| 26 |
from langchain_core.tools import tool
|
| 27 |
from langchain_tavily import TavilySearch
|
| 28 |
|
|
@@ -75,7 +76,7 @@ class BasicAgent:
|
|
| 75 |
|
| 76 |
**Answer Format Rules**
|
| 77 |
- If the answer is a number, output digits only (no commas, no units, no strings like “one”, “twenty three”).
|
| 78 |
-
- If it’s a word or phrase, don't use articles, neither abbreviations (e.g. for cities).
|
| 79 |
- If it’s a comma separated list, output a comma-separated list following the above rules for each element.
|
| 80 |
- **Always** output exactly one line as an answer and nothing else.
|
| 81 |
|
|
@@ -108,7 +109,8 @@ class BasicAgent:
|
|
| 108 |
question=question,
|
| 109 |
messages=[sys_msg, HumanMessage(content=question)]
|
| 110 |
)
|
| 111 |
-
|
|
|
|
| 112 |
final_answer = result["messages"][-1].content
|
| 113 |
print(f"\nFinal Answer: {final_answer}")
|
| 114 |
return final_answer, result["messages"]
|
|
@@ -129,7 +131,7 @@ class BasicAgent:
|
|
| 129 |
def search_tool(question: str, max_length: int = 100000) -> str:
|
| 130 |
print(f"\nCalling search tool with: {question}, max_lentgh: {max_length}")
|
| 131 |
search_ = TavilySearch(
|
| 132 |
-
max_results=
|
| 133 |
topic="general",
|
| 134 |
)
|
| 135 |
info = search_.invoke({"query": question})
|
|
@@ -300,9 +302,10 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 300 |
file_url = f"{api_url}/files/{task_id}"
|
| 301 |
file_name = f"task_file_{task_id}"
|
| 302 |
with open(file_name, "wb") as file:
|
| 303 |
-
response = get(file_url)
|
| 304 |
file.write(response.content)
|
| 305 |
-
except:
|
|
|
|
| 306 |
print("Didn't manage to download a file, probably it's not expected for this task")
|
| 307 |
|
| 308 |
try:
|
|
|
|
| 23 |
|
| 24 |
from langchain_openai import ChatOpenAI
|
| 25 |
from langchain_core.messages import SystemMessage, HumanMessage, AnyMessage
|
| 26 |
+
from langchain_core.runnables.config import RunnableConfig
|
| 27 |
from langchain_core.tools import tool
|
| 28 |
from langchain_tavily import TavilySearch
|
| 29 |
|
|
|
|
| 76 |
|
| 77 |
**Answer Format Rules**
|
| 78 |
- If the answer is a number, output digits only (no commas, no units, no strings like “one”, “twenty three”).
|
| 79 |
+
- If it’s a word or phrase, don't use articles, neither abbreviations (e.g. for cities - New York, not NY).
|
| 80 |
- If it’s a comma separated list, output a comma-separated list following the above rules for each element.
|
| 81 |
- **Always** output exactly one line as an answer and nothing else.
|
| 82 |
|
|
|
|
| 109 |
question=question,
|
| 110 |
messages=[sys_msg, HumanMessage(content=question)]
|
| 111 |
)
|
| 112 |
+
config = RunnableConfig(recursion_limit=10)
|
| 113 |
+
result = self.compiled_graph.invoke(state, config)
|
| 114 |
final_answer = result["messages"][-1].content
|
| 115 |
print(f"\nFinal Answer: {final_answer}")
|
| 116 |
return final_answer, result["messages"]
|
|
|
|
| 131 |
def search_tool(question: str, max_length: int = 100000) -> str:
|
| 132 |
print(f"\nCalling search tool with: {question}, max_lentgh: {max_length}")
|
| 133 |
search_ = TavilySearch(
|
| 134 |
+
max_results=3,
|
| 135 |
topic="general",
|
| 136 |
)
|
| 137 |
info = search_.invoke({"query": question})
|
|
|
|
| 302 |
file_url = f"{api_url}/files/{task_id}"
|
| 303 |
file_name = f"task_file_{task_id}"
|
| 304 |
with open(file_name, "wb") as file:
|
| 305 |
+
response = requests.get(file_url, timeout=15)
|
| 306 |
file.write(response.content)
|
| 307 |
+
except Exception as e:
|
| 308 |
+
print(f"Expection occurred while trying to download {file_name} from {file_url}:", e)
|
| 309 |
print("Didn't manage to download a file, probably it's not expected for this task")
|
| 310 |
|
| 311 |
try:
|