sqfoo commited on
Commit
c60b26f
·
verified ·
1 Parent(s): 8b79a19

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +15 -17
agent.py CHANGED
@@ -278,29 +278,27 @@ class BasicAgent:
278
  If Task ID is included in the question, remember to call the relevant read tools [ie. read_file, excel_read, csv_read, mp3_listen, image_caption]
279
  """
280
  self.tools = [duckduck_websearch, serper_websearch, visit_webpage, wiki_search, text_splitter, youtube_transcript, read_file, excel_read, csv_read, mp3_listen, image_caption, python_tool]
281
- self.model_with_tools = self.model.bind_tools(self.tools)
282
- self.sys_msg = SystemMessage(content=self.sys_prompt)
283
 
284
  self.prompt = ChatPromptTemplate.from_messages([
285
  ("system", self.sys_prompt),
286
  ("human", "{input}")
287
  ])
288
- # self.agent = initialize_agent(
289
- # tools=self.tools,
290
- # llm=self.model,
291
- # agent="zero-shot-react-description", # ReAct agent type
292
- # verbose=True,
293
- # system_prompt=self.prompt,
294
- # handle_parsing_errors="Check your output and make sure it conforms, use the Action/Action Input syntax"
295
- # )
296
- self.graph = self.__graph_compile__()
297
  print("BasicAgent initialized.")
298
 
299
  def __call__(self, task: dict) -> str:
300
  task_id, question, file_name = task["task_id"], task["question"], task["file_name"]
301
  print(f"Agent received question (first 50 chars): {question[:50]}...")
302
- # response = self.agent_exe.invoke({"input": f"Question: {question}"})
303
- # fixed_answer = response['message'][-1].content
304
 
305
  if file_name == "" or file_name is None:
306
  question = question
@@ -308,10 +306,10 @@ class BasicAgent:
308
  question = f"{question} with TASK-ID: {task_id}"
309
  # fixed_answer = self.agent.run(f'{question} with TASK-ID: {task_id}')
310
  # fixed_answer = "This is a default answer."
311
- # fixed_answer = self.agent.run(question)
312
- human_message = [HumanMessage(content=question)]
313
- messages = self.graph.invoke({"messages": human_message})
314
- fixed_answer = messages['messages'][-1].content
315
  print(f"Agent returning fixed answer: {fixed_answer}")
316
  time.sleep(60)
317
  return fixed_answer
 
278
  If Task ID is included in the question, remember to call the relevant read tools [ie. read_file, excel_read, csv_read, mp3_listen, image_caption]
279
  """
280
  self.tools = [duckduck_websearch, serper_websearch, visit_webpage, wiki_search, text_splitter, youtube_transcript, read_file, excel_read, csv_read, mp3_listen, image_caption, python_tool]
281
+ # self.model_with_tools = self.model.bind_tools(self.tools)
282
+ # self.sys_msg = SystemMessage(content=self.sys_prompt)
283
 
284
  self.prompt = ChatPromptTemplate.from_messages([
285
  ("system", self.sys_prompt),
286
  ("human", "{input}")
287
  ])
288
+ self.agent = initialize_agent(
289
+ tools=self.tools,
290
+ llm=self.model,
291
+ agent="zero-shot-react-description", # ReAct agent type
292
+ verbose=True,
293
+ system_prompt=self.prompt,
294
+ handle_parsing_errors="Check your output and make sure it conforms, use the Action/Action Input syntax"
295
+ )
296
+ # self.graph = self.__graph_compile__()
297
  print("BasicAgent initialized.")
298
 
299
  def __call__(self, task: dict) -> str:
300
  task_id, question, file_name = task["task_id"], task["question"], task["file_name"]
301
  print(f"Agent received question (first 50 chars): {question[:50]}...")
 
 
302
 
303
  if file_name == "" or file_name is None:
304
  question = question
 
306
  question = f"{question} with TASK-ID: {task_id}"
307
  # fixed_answer = self.agent.run(f'{question} with TASK-ID: {task_id}')
308
  # fixed_answer = "This is a default answer."
309
+ fixed_answer = self.agent.run(question)
310
+ # human_message = [HumanMessage(content=question)]
311
+ # messages = self.graph.invoke({"messages": human_message})
312
+ # fixed_answer = messages['messages'][-1].content
313
  print(f"Agent returning fixed answer: {fixed_answer}")
314
  time.sleep(60)
315
  return fixed_answer