Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
|
@@ -49,6 +49,42 @@ Tool Use Guidelines:
|
|
| 49 |
# --- Basic Agent Definition ---
|
| 50 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 51 |
class BasicAgent:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def __init__(self):
|
| 53 |
try:
|
| 54 |
hf_api_key = os.getenv("HF_API_KEY")
|
|
|
|
| 49 |
# --- Basic Agent Definition ---
|
| 50 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 51 |
class BasicAgent:
|
| 52 |
+
def __init__(self):
|
| 53 |
+
# Don’t swallow initialization errors silently
|
| 54 |
+
hf_api_key = os.getenv("HF_API_KEY")
|
| 55 |
+
if not hf_api_key:
|
| 56 |
+
raise RuntimeError("HF_API_KEY not set in environment variables.")
|
| 57 |
+
|
| 58 |
+
# Pass the api_key into the HuggingFaceInferenceAPI constructor
|
| 59 |
+
llm = HuggingFaceInferenceAPI(
|
| 60 |
+
model_name="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 61 |
+
api_key=hf_api_key,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
# Build the agent – now self.agent will always be assigned or raise immediately
|
| 65 |
+
self.agent = AgentWorkflow.from_tools_or_functions(
|
| 66 |
+
tools_or_functions=[
|
| 67 |
+
ReverseTextTool(),
|
| 68 |
+
RunPythonFileTool(),
|
| 69 |
+
download_server,
|
| 70 |
+
wiki_tool,
|
| 71 |
+
YoutubeTranscript(),
|
| 72 |
+
DuckDuckGoSearchTool()
|
| 73 |
+
],
|
| 74 |
+
llm=llm,
|
| 75 |
+
system_prompt=SYSTEM_PROMPT,
|
| 76 |
+
)
|
| 77 |
+
print("✅ BasicAgent initialized.")
|
| 78 |
+
|
| 79 |
+
async def __call__(self, input_text: str):
|
| 80 |
+
return await self.agent.run(input_text)
|
| 81 |
+
|
| 82 |
+
async def run(self, input_text: str):
|
| 83 |
+
return await self.agent.run(input_text)
|
| 84 |
+
|
| 85 |
+
async def stream(self, input_text: str):
|
| 86 |
+
async for chunk in self.agent.stream(input_text):
|
| 87 |
+
yield chunk.delta
|
| 88 |
def __init__(self):
|
| 89 |
try:
|
| 90 |
hf_api_key = os.getenv("HF_API_KEY")
|