IamRulo commited on
Commit
4874d03
·
verified ·
1 Parent(s): 5ff294c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -26
app.py CHANGED
@@ -4,14 +4,10 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
7
- # Rulo copycat
8
- from smolagents import(
9
- ToolCallingAgent,
10
- CodeAgent,
11
- DuckDuckGoSearchTool,
12
- InferenceClientModel,
13
- HfApiModel,
14
- )
15
  # Rulo
16
 
17
  # (Keep Constants as is)
@@ -20,33 +16,27 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
20
 
21
  # --- Basic Agent Definition ---
22
  # ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
 
23
  class BasicAgent:
 
24
  def __init__(self):
25
- #rulo copycat
26
- self.model = HfApiModel(
27
- max_tokens=150,
28
- temperature=0.3,
29
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
30
- )
31
- self.agent = ToolCallingAgent(
32
- tools=[DuckDuckGoSearchTool()],
33
- model=self.model,
34
- add_base_tools=True
35
- )
36
- #rulo
37
-
38
  print("BasicAgent initialized.")
 
 
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
  #rulo
44
- fixed_answer = self.agent.run(question)
 
 
 
 
 
 
45
  #rulo
46
 
47
- print(f"Agent returning fixed answer: {fixed_answer}")
48
- return fixed_answer
49
-
50
  def run_and_submit_all( profile: gr.OAuthProfile | None):
51
  """
52
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ # rulo additionally
8
+ from langchain_core.messages import HumanMessage
9
+ from agent import build_graph
10
+
 
 
 
 
11
  # Rulo
12
 
13
  # (Keep Constants as is)
 
16
 
17
  # --- Basic Agent Definition ---
18
  # ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
19
+
20
  class BasicAgent:
21
+ """A LangGraph agent"""
22
  def __init__(self):
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  print("BasicAgent initialized.")
24
+ #rulo
25
+ self.graph = build_graph()
26
 
27
  def __call__(self, question: str) -> str:
28
  print(f"Agent received question (first 50 chars): {question[:50]}...")
 
29
  #rulo
30
+ # Wrap the question in a HumanMessage from langchain_core
31
+ messages = [HumanMessage(content=question)]
32
+ messages = self.graph.invoke({"messages": messages})
33
+ answer = messages['messages'][-1].content
34
+
35
+ print(f"answer: {answer}") #rulo
36
+ return answer[14:]
37
  #rulo
38
 
39
+
 
 
40
  def run_and_submit_all( profile: gr.OAuthProfile | None):
41
  """
42
  Fetches all questions, runs the BasicAgent on them, submits all answers,