Spaces:
Running on Zero
Running on Zero
File size: 3,225 Bytes
cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f cd6addd 2acf84f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #!/usr/bin/env python3
"""CLI test runner for ArkAssistant.
Usage:
# Run a test query against the manager agent:
.venv/bin/python test_agent.py "What is the capital of France and what is the current time there?"
# Sanity check all tools without calling the LLM:
.venv/bin/python test_agent.py --test-tools
The project uses the Hugging Face Inference API and requires HF_TOKEN in .env.
"""
import sys
from tools.get_current_time_in_timezone import get_current_time_in_timezone
from tools.get_weather import get_weather
from tools.search_wikipedia import search_wikipedia
from tools.visit_webpage import VisitWebpageTool
from tools.web_search import DuckDuckGoSearchTool
def _require_result(result: str) -> str:
text = str(result).strip()
if not text:
raise RuntimeError("tool returned an empty result")
if text.lower().startswith("error"):
raise RuntimeError(text)
return text
def run_tools_sanity() -> int:
print("=" * 60)
print("🔬 Running Sanity Check on ArkAssistant Tools (No LLM Calls)")
print("=" * 60)
visit_webpage = VisitWebpageTool()
web_search = DuckDuckGoSearchTool()
failures: list[str] = []
checks = [
("Weather", lambda: get_weather("London")),
("Timezone", lambda: get_current_time_in_timezone("UTC")),
("Wikipedia", lambda: search_wikipedia("Alan Turing")),
("Visit Webpage", lambda: visit_webpage("https://httpbin.org/html")),
("Web Search", lambda: web_search("smolagents Hugging Face")),
]
for name, check in checks:
try:
result = _require_result(check())
preview = result.replace("\n", " ")[:100]
print(f"✅ {name} Tool: {preview}")
except Exception as exc:
failures.append(f"{name}: {exc}")
print(f"❌ {name} Tool Failed: {exc}")
print("=" * 60)
if failures:
print(f"❌ {len(failures)} tool check(s) failed.")
for failure in failures:
print(f" - {failure}")
return 1
print("✅ All tool sanity checks passed.")
return 0
def main() -> int:
args = sys.argv[1:]
if "--test-tools" in args:
return run_tools_sanity()
prompt = " ".join(arg for arg in args if not arg.startswith("--"))
if not prompt:
prompt = "What is the current time in UTC and what is the weather in Paris?"
print(f"No prompt provided. Using default test prompt:\n '{prompt}'\n")
print("🚀 Initializing ArkAssistant Agent...")
try:
from app import agent
print(f"🤖 Running Agent Task: \"{prompt}\"")
print("-" * 60)
response = agent.run(prompt)
print("-" * 60)
print(f"\n🎯 Agent Final Answer:\n{response}")
return 0
except Exception as exc:
message = str(exc)
print(f"\n❌ Error during agent execution: {message}")
if "402" in message or "Payment Required" in message:
print(
"Hint: Hugging Face Inference has no available credits. "
"Add credits/PRO or configure another cloud provider in .env."
)
return 1
if __name__ == "__main__":
sys.exit(main())
|