xarical commited on
Commit
c1f8728
·
1 Parent(s): 2eafa9d
Files changed (1) hide show
  1. CustomAgent.py +25 -25
CustomAgent.py CHANGED
@@ -6,11 +6,32 @@ from BasicAgent import BasicAgent
6
  import os
7
 
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  class CustomAgent(BasicAgent):
10
  def __init__(self):
11
  super().__init__()
12
  self._system_prompt = """\
13
- You are a general AI assistant. I will ask you a question. Report your thoughts and provide an answer using, if appropriate, the tools at your disposal.
14
  Your final answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. Do not provide anything except your final answer.
15
  If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
16
  If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
@@ -18,7 +39,7 @@ If you are asked for a comma separated list, apply the above rules depending of
18
  Question: {question}
19
  """ # System prompt, adapted from the GAIA team's example at https://huggingface.co/spaces/gaia-benchmark/leaderboard
20
  self._model = OpenaiChatModel(
21
- model="llama-3.3-70b-versatile",
22
  api_key=os.environ["GROQ_API_KEY"],
23
  base_url="https://api.groq.com/openai/v1/",
24
  temperature=0.2,
@@ -30,11 +51,11 @@ Question: {question}
30
  """
31
  this is where the magic happens
32
  """
33
- super().__call__(question)
34
  @prompt_chain(
35
  template=self._system_prompt,
36
  model=self._model,
37
- functions=[self.websearch],
38
  )
39
  def _magic(question: str) -> FunctionCall | str:
40
  """
@@ -45,24 +66,3 @@ Question: {question}
45
  result = _magic(question)
46
  print("Agent returning actual answer:", result)
47
  return result
48
-
49
- @staticmethod
50
- def websearch(query: str) -> str:
51
- """
52
- Performs a web search using an external web search API.
53
- Args:
54
- query (str): The search query string.
55
- Returns:
56
- str: The response from the web search API as a string.
57
- """
58
- try:
59
- r = requests.post(
60
- f"{os.environ['WEBSEARCH_API_URL']}/tools/websearch",
61
- json={"query": query}
62
- )
63
- r.raise_for_status()
64
- response = r.text
65
- except Exception as e:
66
- print("Error:", e)
67
- response = "An error has occurred while using websearch, please inform the user of this"
68
- print(f"Agent searched for {query}. Response: {response}")
 
6
  import os
7
 
8
 
9
+ def websearch(query: str) -> str:
10
+ """
11
+ Performs a web search using an external web search API.
12
+ Args:
13
+ query (str): The search query string.
14
+ Returns:
15
+ str: The response from the web search API as a string.
16
+ """
17
+ try:
18
+ r = requests.post(
19
+ f"{os.environ['WEBSEARCH_API_URL']}/tools/websearch",
20
+ json={"query": query}
21
+ )
22
+ r.raise_for_status()
23
+ response = r.text
24
+ except Exception as e:
25
+ print("Error:", e)
26
+ response = "An error has occurred while using websearch, please inform the user of this"
27
+ print(f"Agent searched for {query}. Response: {response}")
28
+
29
+
30
  class CustomAgent(BasicAgent):
31
  def __init__(self):
32
  super().__init__()
33
  self._system_prompt = """\
34
+ You are a general AI assistant. I will ask you a question. Report your thoughts and provide an answer.
35
  Your final answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. Do not provide anything except your final answer.
36
  If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
37
  If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
 
39
  Question: {question}
40
  """ # System prompt, adapted from the GAIA team's example at https://huggingface.co/spaces/gaia-benchmark/leaderboard
41
  self._model = OpenaiChatModel(
42
+ model="llama-3.1-8b-instant",
43
  api_key=os.environ["GROQ_API_KEY"],
44
  base_url="https://api.groq.com/openai/v1/",
45
  temperature=0.2,
 
51
  """
52
  this is where the magic happens
53
  """
54
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
55
  @prompt_chain(
56
  template=self._system_prompt,
57
  model=self._model,
58
+ functions=[websearch],
59
  )
60
  def _magic(question: str) -> FunctionCall | str:
61
  """
 
66
  result = _magic(question)
67
  print("Agent returning actual answer:", result)
68
  return result