Spaces:
Sleeping
Sleeping
Nguyen Nhu Trung
commited on
Commit
·
1bf4291
1
Parent(s):
1c89ca6
remove delay and print
Browse files
agent.py
CHANGED
|
@@ -36,6 +36,7 @@ repl_tool = Tool(
|
|
| 36 |
tavily_search_tool = TavilySearch(
|
| 37 |
max_results=5,
|
| 38 |
topic="general",
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
# Initialize Tavily Extract Tool
|
|
@@ -92,9 +93,27 @@ def wiki_search(query: str) -> str:
|
|
| 92 |
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
| 93 |
for doc in search_docs
|
| 94 |
])
|
| 95 |
-
print(formatted_search_docs)
|
| 96 |
return {"wiki_results": formatted_search_docs}
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
# @tool
|
| 99 |
# def web_search(query: str) -> str:
|
| 100 |
# """Search Tavily for a query and return maximum 3 results.
|
|
@@ -127,19 +146,12 @@ tools = [
|
|
| 127 |
tavily_extract_tool,
|
| 128 |
repl_tool,
|
| 129 |
read_excel_file,
|
| 130 |
-
transcribe_audio
|
|
|
|
| 131 |
]
|
| 132 |
|
| 133 |
|
| 134 |
-
|
| 135 |
-
llm = ChatGoogleGenerativeAI(
|
| 136 |
-
model="gemini-2.0-flash",
|
| 137 |
-
temperature=0.7,
|
| 138 |
-
max_tokens=None,
|
| 139 |
-
timeout=None,
|
| 140 |
-
max_retries=2,
|
| 141 |
-
# other params...
|
| 142 |
-
)
|
| 143 |
llm_with_tools = llm.bind_tools(tools)
|
| 144 |
|
| 145 |
def assistant(state: MessagesState):
|
|
@@ -147,7 +159,6 @@ def assistant(state: MessagesState):
|
|
| 147 |
return {"messages": [llm_with_tools.invoke(state["messages"])]}
|
| 148 |
|
| 149 |
def final_answer(answer):
|
| 150 |
-
print(f"ANSWER: {answer}")
|
| 151 |
return answer.replace("FINAL ANSWER:","")
|
| 152 |
|
| 153 |
builder = StateGraph(MessagesState)
|
|
@@ -173,6 +184,7 @@ if __name__ == "__main__":
|
|
| 173 |
# question = "What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?"
|
| 174 |
# question = "Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations."
|
| 175 |
question = "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia."
|
|
|
|
| 176 |
# getmessages = [HumanMessage(content=question)]
|
| 177 |
# messages = graph.invoke({"messages": messages})
|
| 178 |
# for m in messages["messages"]:
|
|
|
|
| 36 |
tavily_search_tool = TavilySearch(
|
| 37 |
max_results=5,
|
| 38 |
topic="general",
|
| 39 |
+
search_depth="advanced"
|
| 40 |
)
|
| 41 |
|
| 42 |
# Initialize Tavily Extract Tool
|
|
|
|
| 93 |
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
| 94 |
for doc in search_docs
|
| 95 |
])
|
|
|
|
| 96 |
return {"wiki_results": formatted_search_docs}
|
| 97 |
|
| 98 |
+
@tool
|
| 99 |
+
def solve_logic_or_math_problem(problem: str) -> str:
|
| 100 |
+
"""Solve logic or math problem.
|
| 101 |
+
|
| 102 |
+
Args:
|
| 103 |
+
problem: The problem statement."""
|
| 104 |
+
print('solve')
|
| 105 |
+
llm = ChatGoogleGenerativeAI(
|
| 106 |
+
model="gemini-2.0-flash",
|
| 107 |
+
temperature=0.1,
|
| 108 |
+
max_tokens=None,
|
| 109 |
+
timeout=None,
|
| 110 |
+
max_retries=2,
|
| 111 |
+
# other params...
|
| 112 |
+
)
|
| 113 |
+
response = llm.invoke(problem)
|
| 114 |
+
return response.content
|
| 115 |
+
|
| 116 |
+
|
| 117 |
# @tool
|
| 118 |
# def web_search(query: str) -> str:
|
| 119 |
# """Search Tavily for a query and return maximum 3 results.
|
|
|
|
| 146 |
tavily_extract_tool,
|
| 147 |
repl_tool,
|
| 148 |
read_excel_file,
|
| 149 |
+
transcribe_audio,
|
| 150 |
+
solve_logic_or_math_problem
|
| 151 |
]
|
| 152 |
|
| 153 |
|
| 154 |
+
llm = ChatGroq(model="qwen-qwq-32b", temperature=0.1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
llm_with_tools = llm.bind_tools(tools)
|
| 156 |
|
| 157 |
def assistant(state: MessagesState):
|
|
|
|
| 159 |
return {"messages": [llm_with_tools.invoke(state["messages"])]}
|
| 160 |
|
| 161 |
def final_answer(answer):
|
|
|
|
| 162 |
return answer.replace("FINAL ANSWER:","")
|
| 163 |
|
| 164 |
builder = StateGraph(MessagesState)
|
|
|
|
| 184 |
# question = "What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?"
|
| 185 |
# question = "Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations."
|
| 186 |
question = "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia."
|
| 187 |
+
question ="Given this table defining * on the set S = {a, b, c, d, e}\n\n|*|a|b|c|d|e|\n|---|---|---|---|---|---|\n|a|a|b|c|b|d|\n|b|b|c|a|e|c|\n|c|c|a|b|b|a|\n|d|b|e|b|e|d|\n|e|d|b|a|d|c|\n\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order."
|
| 188 |
# getmessages = [HumanMessage(content=question)]
|
| 189 |
# messages = graph.invoke({"messages": messages})
|
| 190 |
# for m in messages["messages"]:
|
app.py
CHANGED
|
@@ -77,7 +77,6 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 77 |
answers_payload = []
|
| 78 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 79 |
for item in questions_data:
|
| 80 |
-
time.sleep(10)
|
| 81 |
task_id = item.get("task_id")
|
| 82 |
question_text = item.get("question")
|
| 83 |
if not task_id or question_text is None:
|
|
|
|
| 77 |
answers_payload = []
|
| 78 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 79 |
for item in questions_data:
|
|
|
|
| 80 |
task_id = item.get("task_id")
|
| 81 |
question_text = item.get("question")
|
| 82 |
if not task_id or question_text is None:
|