okmich commited on
Commit
1acf3b1
·
verified ·
1 Parent(s): 716e4df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -5
app.py CHANGED
@@ -8,16 +8,53 @@ import pandas as pd
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
- # --- Basic Agent Definition ---
12
- # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
 
 
 
 
 
 
 
 
 
 
13
  class BasicAgent:
14
  def __init__(self):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  print("BasicAgent initialized.")
 
 
16
  def __call__(self, question: str) -> str:
17
- print(f"Agent received question (first 50 chars): {question[:50]}...")
18
  fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
 
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
+ from agents import tool_list
12
+
13
+
14
+ # Generate the AgentState and Agent graph
15
+ class AgentState(TypedDict):
16
+ messages: Annotated[list[AnyMessage], add_messages]
17
+
18
+ def get_assistant(chat_with_tools):
19
+ def assistant(state: AgentState):
20
+ return {
21
+ "messages": [chat_with_tools.invoke(state["messages"])],
22
+ }
23
+ return assistant
24
+
25
  class BasicAgent:
26
  def __init__(self):
27
+ llm = HuggingFaceEndpoint(repo_id="Qwen/Qwen2.5-Coder-32B-Instruct",)
28
+ chat = ChatHuggingFace(llm=llm, verbose=True)
29
+
30
+ # define tools
31
+ tools = tool_list()
32
+ chat_with_tools = chat.bind_tools(tools)
33
+
34
+ ## The graph
35
+ graph_builder = StateGraph(AgentState)
36
+
37
+ chat_assistant_tool = get_assistant(chat_with_tools)
38
+
39
+ graph_builder.add_node("assistant", chat_assistant_tool)
40
+ graph_builder.add_node("tools", ToolNode(tools))
41
+
42
+ # edges
43
+ graph_builder.add_edge(START, "assistant")
44
+ graph_builder.add_conditional_edges("assistant", tools_condition)
45
+ graph_builder.add_edge("tools", "assistant")
46
+
47
+ self.okmich_agent = graph_builder.compile()
48
+
49
  print("BasicAgent initialized.")
50
+
51
+
52
  def __call__(self, question: str) -> str:
53
+ messages = [HumanMessage(content=question)]
54
  fixed_answer = "This is a default answer."
55
+ _response = self.okmich_agent.invoke({"messages": messages})
56
+ return _response['messages'][-1].content if _response else fixed_answer
57
+
58
 
59
  def run_and_submit_all( profile: gr.OAuthProfile | None):
60
  """