Commit
·
10ba265
1
Parent(s):
f6fc677
+ merged with gradio for benchmarking
Browse files- agents.py +11 -5
- app.py +5 -4
- system_prompt.txt +1 -0
agents.py
CHANGED
|
@@ -35,7 +35,7 @@ from tools import (
|
|
| 35 |
|
| 36 |
load_dotenv("env.local")
|
| 37 |
|
| 38 |
-
class
|
| 39 |
def __init__(self):
|
| 40 |
# Tool initializations using imported functions
|
| 41 |
self.tavily_tool = get_tavily_tool()
|
|
@@ -46,11 +46,17 @@ class AlfredAgent:
|
|
| 46 |
self.search_tool = get_search_tool()
|
| 47 |
self.calculator_tool = get_calculator_tool()
|
| 48 |
self.hub_stats_tool = get_hub_stats_tool()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
# LLM and agent workflow
|
| 50 |
self.llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 51 |
self.alfred = AgentWorkflow.from_tools_or_functions(
|
| 52 |
[*self.search_tool, *self.calculator_tool, self.wikipedia_tool, self.arxiv_tool, self.hub_stats_tool],
|
| 53 |
-
llm=self.llm
|
|
|
|
|
|
|
| 54 |
)
|
| 55 |
|
| 56 |
LANGFUSE_AUTH=base64.b64encode(f"{os.getenv('LANGFUSE_PUBLIC_KEY')}:{os.getenv('LANGFUSE_SECRET_KEY')}".encode()).decode()
|
|
@@ -93,12 +99,12 @@ class AlfredAgent:
|
|
| 93 |
|
| 94 |
def main():
|
| 95 |
|
| 96 |
-
agent =
|
| 97 |
-
query = "
|
| 98 |
print(f"Running query: {query}")
|
| 99 |
response = asyncio.run(agent.run_query(query))
|
| 100 |
print("\n🎩 Agents's Response:")
|
| 101 |
-
|
| 102 |
|
| 103 |
if __name__ == "__main__":
|
| 104 |
main()
|
|
|
|
| 35 |
|
| 36 |
load_dotenv("env.local")
|
| 37 |
|
| 38 |
+
class LlamaIndexAgent:
|
| 39 |
def __init__(self):
|
| 40 |
# Tool initializations using imported functions
|
| 41 |
self.tavily_tool = get_tavily_tool()
|
|
|
|
| 46 |
self.search_tool = get_search_tool()
|
| 47 |
self.calculator_tool = get_calculator_tool()
|
| 48 |
self.hub_stats_tool = get_hub_stats_tool()
|
| 49 |
+
with open("system_prompt.txt", "r") as f:
|
| 50 |
+
self.system_prompt = f.read()
|
| 51 |
+
|
| 52 |
+
print(self.system_prompt)
|
| 53 |
# LLM and agent workflow
|
| 54 |
self.llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 55 |
self.alfred = AgentWorkflow.from_tools_or_functions(
|
| 56 |
[*self.search_tool, *self.calculator_tool, self.wikipedia_tool, self.arxiv_tool, self.hub_stats_tool],
|
| 57 |
+
llm=self.llm,
|
| 58 |
+
system_prompt=self.system_prompt
|
| 59 |
+
# verbose=True
|
| 60 |
)
|
| 61 |
|
| 62 |
LANGFUSE_AUTH=base64.b64encode(f"{os.getenv('LANGFUSE_PUBLIC_KEY')}:{os.getenv('LANGFUSE_SECRET_KEY')}".encode()).decode()
|
|
|
|
| 99 |
|
| 100 |
def main():
|
| 101 |
|
| 102 |
+
agent = LlamaIndexAgent()
|
| 103 |
+
query = "what is the capital of maharashtra?"
|
| 104 |
print(f"Running query: {query}")
|
| 105 |
response = asyncio.run(agent.run_query(query))
|
| 106 |
print("\n🎩 Agents's Response:")
|
| 107 |
+
print(response)
|
| 108 |
|
| 109 |
if __name__ == "__main__":
|
| 110 |
main()
|
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -12,12 +12,13 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 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 |
-
|
| 19 |
-
print(f"Agent returning fixed answer: {
|
| 20 |
-
return
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from agents import LlamaIndexAgent
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
self.agent = LlamaIndexAgent()
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
def __call__(self, question: str) -> str:
|
| 18 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 19 |
+
response = self.agent.run_query(question)
|
| 20 |
+
print(f"Agent returning fixed answer: {response}")
|
| 21 |
+
return response
|
| 22 |
|
| 23 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 24 |
"""
|
system_prompt.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
give single word answer and reply.
|