Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
neoguojing committed Dec 16, 2024
1 parent eaa6234 commit 9130754
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
9 changes: 2 additions & 7 deletions agi/tasks/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

def _modify_state_messages(state: AgentState):
return prompt.invoke({"messages": state["messages"]}).to_messages() + [
return prompt.invoke({"messages": state["messages"],"language":"chinese"}).to_messages() + [
("user", "Also say 'Pandamonium!' after the answer.")
]

Expand All @@ -24,11 +24,6 @@ def create_react_agent_task(llm):
tools,state_modifier=_modify_state_messages,
checkpointer=memory,
store=InMemoryStore())
langgraph_agent_executor.step_timeout = 2
# langgraph_agent_executor.step_timeout = 2
return langgraph_agent_executor

# messages = langgraph_agent_executor.invoke({"messages": [("human", query)]})
# {
# "input": query,
# "output": messages["messages"][-1].content,
# }
12 changes: 6 additions & 6 deletions agi/tasks/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
os.environ["ALPHAVANTAGE_API_KEY"] = '1JXIUYN26HYID5Y9'

search = DuckDuckGoSearchRun()
WolframAlpha = WolframAlphaAPIWrapper()
# WolframAlpha = WolframAlphaAPIWrapper()
arxiv = ArxivAPIWrapper()
alpha_vantage = AlphaVantageAPIWrapper()

Expand Down Expand Up @@ -112,11 +112,11 @@ def parse_stock_code(input:str):
func=search.run,
description="Useful for when you need to answer questions about current events"
),
Tool(
name="Math",
func=WolframAlpha.run,
description="Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life."
),
# Tool(
# name="Math",
# func=WolframAlpha.run,
# description="Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life."
# ),
Tool(
name="arxiv",
func=arxiv.run,
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pypdf==5.1.0
duckduckgo-search==6.3.7
beautifulsoup4==4.12.3
rank_bm25==0.2.2
arxiv==2.1.3
pytest


Expand Down
29 changes: 15 additions & 14 deletions tests/tasks/task_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ class TestAgent(unittest.TestCase):
def setUp(self):
self.agent = TaskFactory.create_task(TASK_AGENT)
self.RECURSION_LIMIT = 5
self.config={"configurable": {"user_id": "test", "conversation_id": "1"},"recursion_limit": self.RECURSION_LIMIT }
self.config={"configurable": {"user_id": "test", "conversation_id": "1","thread_id": "test-thread"},
"recursion_limit": self.RECURSION_LIMIT }
def test_agent(self):
query = "下周上海的天气如何?"
query = "查询tesla股票价格"
try:
messages = self.agent.invoke({"messages": [("human", query)]},config=self.config)
messages = self.agent.invoke({"language":"chinese","messages": [("human", query)]},config=self.config)
print(messages)
except GraphRecursionError:
print({"input": query, "output": "Agent stopped due to max iterations."})

# def test_agent_steam(self):
# query = "下周上海的天气如何?"
# try:
# for chunk in self.agent.stream(
# {"messages": [("human", query)]},
# config=self.config,
# stream_mode="values",
# ):
# print(chunk["messages"][-1])
# except GraphRecursionError:
# print({"input": query, "output": "Agent stopped due to max iterations."})
def test_agent_steam(self):
query = "下周上海的天气如何?"
try:
for chunk in self.agent.stream(
{"messages": [("human", query)]},
config=self.config,
stream_mode="values",
):
print(chunk["messages"][-1])
except GraphRecursionError:
print({"input": query, "output": "Agent stopped due to max iterations."})

0 comments on commit 9130754

Please sign in to comment.