Antoine101 commited on
Commit
fee0f4a
·
verified ·
1 Parent(s): 75dbf87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -11,19 +11,19 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
  # --- Basic Agent Definition ---
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
 
 
 
 
14
  class BasicAgent:
15
- def __init__(self):
16
- llm = HuggingFaceEndpoint(repo_id="Qwen/Qwen2.5-Coder-32B-Instruct")
17
  chat = ChatHuggingFace(llm=llm, verbose=True)
18
- tools = [guest_info_tool]
19
  chat_with_tools = chat.bind_tools(tools)
20
- self.builder = StateGraph(AgentState)
21
- self.builder.add_node("assistant", assistant)
22
- self.builder.add_node("tools", ToolNode(tools))
23
- self.builder.add_edge(START, "assistant")
24
- self.builder.add_conditional_edges("assistant", tools_condition)
25
- self.builder.add_edge("tools", "assistant")
26
- self.builder.compile()
27
  print("BasicAgent initialized.")
28
  def __call__(self, question: str) -> str:
29
  print(f"Agent received question (first 50 chars): {question[:50]}...")
@@ -33,6 +33,15 @@ class BasicAgent:
33
  fixed_answer = "This is a default answer."
34
  print(f"Agent returning answer: {response}")
35
 
 
 
 
 
 
 
 
 
 
36
  return fixed_answer
37
 
38
  def run_and_submit_all( profile: gr.OAuthProfile | None):
@@ -56,7 +65,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
56
 
57
  # 1. Instantiate Agent ( modify this part to create your agent)
58
  try:
59
- agent = BasicAgent()
60
  except Exception as e:
61
  print(f"Error instantiating agent: {e}")
62
  return f"Error initializing agent: {e}", None
 
11
 
12
  # --- Basic Agent Definition ---
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
+
15
+ def assistant(state: AgentState):
16
+ return {
17
+ "messages": [chat_with_tools.invoke(state["messages"])],
18
+ }
19
+
20
  class BasicAgent:
21
+ def __init__(self, llm_checkpoint):
22
+ llm = HuggingFaceEndpoint(repo_id=llm_checkpoint)
23
  chat = ChatHuggingFace(llm=llm, verbose=True)
24
+ self.tools = [guest_info_tool]
25
  chat_with_tools = chat.bind_tools(tools)
26
+ self.graph = self._build_graph()
 
 
 
 
 
 
27
  print("BasicAgent initialized.")
28
  def __call__(self, question: str) -> str:
29
  print(f"Agent received question (first 50 chars): {question[:50]}...")
 
33
  fixed_answer = "This is a default answer."
34
  print(f"Agent returning answer: {response}")
35
 
36
+ def _build_graph():
37
+ self.builder = StateGraph(AgentState)
38
+ self.builder.add_node("assistant", assistant)
39
+ self.builder.add_node("tools", ToolNode(self.tools))
40
+ self.builder.add_edge(START, "assistant")
41
+ self.builder.add_conditional_edges("assistant", tools_condition)
42
+ self.builder.add_edge("tools", "assistant")
43
+ self.builder.compile()
44
+
45
  return fixed_answer
46
 
47
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
65
 
66
  # 1. Instantiate Agent ( modify this part to create your agent)
67
  try:
68
+ agent = BasicAgent(llm_checkpoint="Qwen/Qwen2.5-Coder-32B-Instruct")
69
  except Exception as e:
70
  print(f"Error instantiating agent: {e}")
71
  return f"Error initializing agent: {e}", None