wishwakankanamg commited on
Commit
2247d95
·
1 Parent(s): 5c274bd
Files changed (1) hide show
  1. app.py +17 -67
app.py CHANGED
@@ -1,86 +1,36 @@
 
1
  import os
 
2
  import gradio as gr
3
  import requests
4
- import inspect
5
  import pandas as pd
6
- import os
7
- import yaml
8
- from tools_agent import ReverseTextTool, TableCommutativityTool, VegetableListTool, ExcelSumFoodTool
9
- from smolagents import (
10
- CodeAgent,
11
- OpenAIServerModel,
12
- DuckDuckGoSearchTool,
13
- FinalAnswerTool,
14
- PythonInterpreterTool,
15
- HfApiModel
16
- )
17
- from huggingface_hub import login, InferenceClient
18
 
19
  # (Keep Constants as is)
20
  # --- Constants ---
21
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
22
 
23
  # --- Basic Agent Definition ---
 
24
 
25
 
26
- # --- Agent Definition ---
27
  class BasicAgent:
 
28
  def __init__(self):
29
- print("Initializing BasicAgent with tools...")
30
-
31
- # Load OpenAI token from environment
32
- openai_token = os.getenv("HF_TOKEN")
33
- if not openai_token:
34
- raise ValueError("Missing API token!")
35
-
36
- # Initialize model and tools
37
-
38
- # model = HfApiModel(
39
- # model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
40
- # token=openai_token,
41
- # max_tokens=5000,
42
- # provider="together",
43
- # )
44
-
45
- client = InferenceClient(
46
- provider="together",
47
- api_key=openai_token,
48
- )
49
-
50
- # model = OpenAIServerModel(
51
- # #api_base="openai",
52
- # api_key=openai_token,
53
- # model_id="gpt-4.1"
54
- # )
55
- search_tool = DuckDuckGoSearchTool()
56
- final_answer_tool = FinalAnswerTool()
57
- reverse_tool = ReverseTextTool()
58
- table_tool = TableCommutativityTool()
59
- veg_tool = VegetableListTool()
60
- python_tool = PythonInterpreterTool()
61
- exfood_tool = ExcelSumFoodTool()
62
-
63
- # Load system prompt templates
64
- with open("prompts.yaml", "r") as stream:
65
- prompt_templates = yaml.safe_load(stream)
66
-
67
- # Build the agent
68
- self.agent = CodeAgent(
69
- model=client,
70
- prompt_templates=prompt_templates,
71
- tools=[search_tool, reverse_tool, table_tool, veg_tool, python_tool, exfood_tool], #final_answer_tool
72
- add_base_tools=True,
73
- planning_interval=None,
74
- name = "GoodAgent",
75
- max_steps=10,
76
- verbosity_level=1,
77
- )
78
 
79
  def __call__(self, question: str) -> str:
80
- print(f"Agent received question (first 50 chars): {question}...")
81
- answer = self.agent(question)
82
- print(f"Agent returning answer: {answer}")
83
- return answer
 
 
 
84
 
85
  def run_and_submit_all( profile: gr.OAuthProfile | None):
86
  """
 
1
+ """ Basic Agent Evaluation Runner"""
2
  import os
3
+ import inspect
4
  import gradio as gr
5
  import requests
 
6
  import pandas as pd
7
+ from langchain_core.messages import HumanMessage
8
+ from agent import build_graph
9
+
10
+
 
 
 
 
 
 
 
 
11
 
12
  # (Keep Constants as is)
13
  # --- Constants ---
14
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
15
 
16
  # --- Basic Agent Definition ---
17
+ # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
18
 
19
 
 
20
  class BasicAgent:
21
+ """A langgraph agent."""
22
  def __init__(self):
23
+ print("BasicAgent initialized.")
24
+ self.graph = build_graph()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def __call__(self, question: str) -> str:
27
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
28
+ # Wrap the question in a HumanMessage from langchain_core
29
+ messages = [HumanMessage(content=question)]
30
+ messages = self.graph.invoke({"messages": messages})
31
+ answer = messages['messages'][-1].content
32
+ return answer[14:]
33
+
34
 
35
  def run_and_submit_all( profile: gr.OAuthProfile | None):
36
  """