sqfoo commited on
Commit
5cbede4
·
verified ·
1 Parent(s): b21ef12

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +29 -19
agent.py CHANGED
@@ -7,7 +7,7 @@ from langchain_google_genai import ChatGoogleGenerativeAI
7
  from langchain_groq import ChatGroq
8
  from langchain_core.tools import tool
9
  from langchain_core.messages import HumanMessage, SystemMessage
10
- from langchain_core.prompts import ChatPromptTemplate
11
  from langgraph.prebuilt import ToolNode
12
  from langgraph.prebuilt import tools_condition
13
 
@@ -237,6 +237,20 @@ def divide(a: float, b: float) -> float:
237
  # - subtract: Subtract A by B with passing A as the first argument
238
  # - divide: Divide A by B with passing A as the first argument
239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  # ("human", f"Question: {question}\nReport to validate: {final_answer}")
241
  class BasicAgent:
242
  def __init__(self):
@@ -267,31 +281,27 @@ class BasicAgent:
267
  If you are asked for a string, don't use articles, neither abbreviations (eg. for cities), and write the digits in plain text unless specified otherwise.
268
  If you are asked for a comma separated list, apply the above rules depending of whether the element to put in the list is a number or a string.
269
 
270
- You have access to the following tools:
271
- - serper_websearch: web search the content of the query by passing the query as input with Serper Search Engine
272
- - duckduck_websearch: web search the content of the query by passing the query as input with DuckDuckGo Search Engine
273
- - visit_webpage: visit the given webpage url by passing the url as input
274
- - wiki_search: wiki search the content of the query by passing the query as input if the question asks for wiki search it
275
- - text_splitter: split text into chunks
276
- - youtube_transcript: fetch the transcript of the Youtube video by passing the video url as input if the question asks for watching a Youtube video
277
- - read_file: read the content of the attached file by passing the TASK-ID as input
278
- - excel_read: read the content of the attached excel file by passing the TASK-ID as input
279
- - csv_read: read the content of the attached csv file by passing the TASK-ID as input
280
- - mp3_listen: listen to the content of the attached mp3 file by passing the TASK-ID as input
281
- - image_caption: understand the visual content of the attached image by passing the TASK-ID as input
282
- - run_python: run the python code
283
-
284
  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]
285
  Note: python_tool is called when the question mentions the term "Python" or any math calculation.
 
 
 
 
 
 
286
  """
287
  self.tools = [duckduck_websearch, serper_websearch, visit_webpage, wiki_search, text_splitter, youtube_transcript, read_file, excel_read, csv_read, mp3_listen, image_caption, run_python]
288
  # self.model_with_tools = self.model.bind_tools(self.tools)
289
  # self.sys_msg = SystemMessage(content=self.sys_prompt)
290
 
291
- self.prompt = ChatPromptTemplate.from_messages([
292
- ("system", self.sys_prompt),
293
- ("human", "{input}")
294
- ])
 
 
 
 
295
  # self.agent = initialize_agent(
296
  # tools=self.tools,
297
  # llm=self.model,
 
7
  from langchain_groq import ChatGroq
8
  from langchain_core.tools import tool
9
  from langchain_core.messages import HumanMessage, SystemMessage
10
+ from langchain_core.prompts import ChatPromptTemplate, PromptTemplate
11
  from langgraph.prebuilt import ToolNode
12
  from langgraph.prebuilt import tools_condition
13
 
 
237
  # - subtract: Subtract A by B with passing A as the first argument
238
  # - divide: Divide A by B with passing A as the first argument
239
 
240
+ # You have access to the following tools:
241
+ # - serper_websearch: web search the content of the query by passing the query as input with Serper Search Engine
242
+ # - duckduck_websearch: web search the content of the query by passing the query as input with DuckDuckGo Search Engine
243
+ # - visit_webpage: visit the given webpage url by passing the url as input
244
+ # - wiki_search: wiki search the content of the query by passing the query as input if the question asks for wiki search it
245
+ # - text_splitter: split text into chunks
246
+ # - youtube_transcript: fetch the transcript of the Youtube video by passing the video url as input if the question asks for watching a Youtube video
247
+ # - read_file: read the content of the attached file by passing the TASK-ID as input
248
+ # - excel_read: read the content of the attached excel file by passing the TASK-ID as input
249
+ # - csv_read: read the content of the attached csv file by passing the TASK-ID as input
250
+ # - mp3_listen: listen to the content of the attached mp3 file by passing the TASK-ID as input
251
+ # - image_caption: understand the visual content of the attached image by passing the TASK-ID as input
252
+ # - run_python: run the python code
253
+
254
  # ("human", f"Question: {question}\nReport to validate: {final_answer}")
255
  class BasicAgent:
256
  def __init__(self):
 
281
  If you are asked for a string, don't use articles, neither abbreviations (eg. for cities), and write the digits in plain text unless specified otherwise.
282
  If you are asked for a comma separated list, apply the above rules depending of whether the element to put in the list is a number or a string.
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  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]
285
  Note: python_tool is called when the question mentions the term "Python" or any math calculation.
286
+
287
+ Follow this format in your response:
288
+ THOUGHT: [Describe your reasoning here]
289
+ ACTION: [Specify the action/tool to use and any relevant input]
290
+ OBSERVATIOn: [Result of the action/tool, provided by the system]
291
+ FINAL ANSWER: [Provide your final response to the user]
292
  """
293
  self.tools = [duckduck_websearch, serper_websearch, visit_webpage, wiki_search, text_splitter, youtube_transcript, read_file, excel_read, csv_read, mp3_listen, image_caption, run_python]
294
  # self.model_with_tools = self.model.bind_tools(self.tools)
295
  # self.sys_msg = SystemMessage(content=self.sys_prompt)
296
 
297
+ # self.prompt = ChatPromptTemplate.from_messages([
298
+ # ("system", self.sys_prompt),
299
+ # ("human", "{input}")
300
+ # ])
301
+ self.prompt = PromptTemplate(
302
+ input_variables=["input", "tool_names"],
303
+ template=self.sys_prompt
304
+ )
305
  # self.agent = initialize_agent(
306
  # tools=self.tools,
307
  # llm=self.model,