marin-iuga commited on
Commit
c9d0d89
·
verified ·
1 Parent(s): 86d3e53

Added core agent functionality.

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -18,30 +18,39 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
18
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
19
  class BasicAgent:
20
  def __init__(self):
21
- print("BasicAgent initialized.")
22
-
23
- model_api_key = os.getenv("OPENAI_API_KEY")
24
 
 
25
  model = OpenAIServerModel(
26
  model_id="gpt-4o-mini-2024-07-18",
27
  api_key = model_api_key
28
  )
 
29
 
30
  self.tools = [
31
  DuckDuckGoSearchTool()
32
  ]
 
33
 
34
  self.agent = CodeAgent(
35
  model = model,
36
  tools = self.tools,
37
  add_base_tools=True # Add basic tools like math
38
  )
 
39
 
40
  def __call__(self, question: str) -> str:
41
  print(f"Agent received question (first 50 chars): {question[:50]}...")
42
- fixed_answer = "This is a default answer."
43
- print(f"Agent returning fixed answer: {fixed_answer}")
44
- return fixed_answer
 
 
 
 
 
 
 
45
 
46
  def run_and_submit_all( profile: gr.OAuthProfile | None):
47
  """
 
18
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
19
  class BasicAgent:
20
  def __init__(self):
21
+ print("Starting the initialization of model.")
 
 
22
 
23
+ model_api_key = os.getenv("OPENAI_API_KEY")
24
  model = OpenAIServerModel(
25
  model_id="gpt-4o-mini-2024-07-18",
26
  api_key = model_api_key
27
  )
28
+ print("Core model has been initialized.")
29
 
30
  self.tools = [
31
  DuckDuckGoSearchTool()
32
  ]
33
+ print("Agent tools have been initialized.")
34
 
35
  self.agent = CodeAgent(
36
  model = model,
37
  tools = self.tools,
38
  add_base_tools=True # Add basic tools like math
39
  )
40
+ print("Core agent has been initialized.")
41
 
42
  def __call__(self, question: str) -> str:
43
  print(f"Agent received question (first 50 chars): {question[:50]}...")
44
+ try:
45
+ # send the question content to the agent
46
+ answer = self.agent.run(question)
47
+ print(f"Agent returning fixed answer: {answer}")
48
+
49
+ # return the answer
50
+ return answer
51
+ except Exception as e:
52
+ print(f"Error running agent {str(e)}")
53
+
54
 
55
  def run_and_submit_all( profile: gr.OAuthProfile | None):
56
  """