Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit ·
d70b208
1
Parent(s): 60a3755
Fix imports and add frontend to gitignore
Browse files- Change backend imports from absolute to relative for local dev
- Update Dockerfile to run from backend directory with PYTHONPATH=/app
- Add frontend/node_modules and frontend/dist to gitignore
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- .gitignore +6 -0
- Dockerfile +5 -3
- backend/main.py +2 -2
- backend/routes/agent.py +3 -3
- backend/session_manager.py +1 -1
- frontend/package-lock.json +0 -0
- test_whoosh_search.py +61 -0
- testing.py +158 -0
.gitignore
CHANGED
|
@@ -18,3 +18,9 @@ hf-agent-leaderboard/
|
|
| 18 |
.cursor/
|
| 19 |
session_logs/
|
| 20 |
skills/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
.cursor/
|
| 19 |
session_logs/
|
| 20 |
skills/
|
| 21 |
+
|
| 22 |
+
# Frontend
|
| 23 |
+
frontend/node_modules/
|
| 24 |
+
frontend/dist/
|
| 25 |
+
frontend/.cache/
|
| 26 |
+
frontend/*.local
|
Dockerfile
CHANGED
|
@@ -44,10 +44,12 @@ USER user
|
|
| 44 |
# Set environment
|
| 45 |
ENV HOME=/home/user \
|
| 46 |
PATH=/home/user/.local/bin:$PATH \
|
| 47 |
-
PYTHONUNBUFFERED=1
|
|
|
|
| 48 |
|
| 49 |
# Expose port
|
| 50 |
EXPOSE 7860
|
| 51 |
|
| 52 |
-
# Run the application
|
| 53 |
-
|
|
|
|
|
|
| 44 |
# Set environment
|
| 45 |
ENV HOME=/home/user \
|
| 46 |
PATH=/home/user/.local/bin:$PATH \
|
| 47 |
+
PYTHONUNBUFFERED=1 \
|
| 48 |
+
PYTHONPATH=/app
|
| 49 |
|
| 50 |
# Expose port
|
| 51 |
EXPOSE 7860
|
| 52 |
|
| 53 |
+
# Run the application from backend directory
|
| 54 |
+
WORKDIR /app/backend
|
| 55 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
backend/main.py
CHANGED
|
@@ -9,8 +9,8 @@ from fastapi import FastAPI
|
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
from fastapi.staticfiles import StaticFiles
|
| 11 |
|
| 12 |
-
from
|
| 13 |
-
from
|
| 14 |
|
| 15 |
# Configure logging
|
| 16 |
logging.basicConfig(
|
|
|
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
from fastapi.staticfiles import StaticFiles
|
| 11 |
|
| 12 |
+
from routes.agent import router as agent_router
|
| 13 |
+
from routes.auth import router as auth_router
|
| 14 |
|
| 15 |
# Configure logging
|
| 16 |
logging.basicConfig(
|
backend/routes/agent.py
CHANGED
|
@@ -4,15 +4,15 @@ import logging
|
|
| 4 |
|
| 5 |
from fastapi import APIRouter, HTTPException, WebSocket, WebSocketDisconnect
|
| 6 |
|
| 7 |
-
from
|
| 8 |
ApprovalRequest,
|
| 9 |
HealthResponse,
|
| 10 |
SessionInfo,
|
| 11 |
SessionResponse,
|
| 12 |
SubmitRequest,
|
| 13 |
)
|
| 14 |
-
from
|
| 15 |
-
from
|
| 16 |
|
| 17 |
logger = logging.getLogger(__name__)
|
| 18 |
|
|
|
|
| 4 |
|
| 5 |
from fastapi import APIRouter, HTTPException, WebSocket, WebSocketDisconnect
|
| 6 |
|
| 7 |
+
from models import (
|
| 8 |
ApprovalRequest,
|
| 9 |
HealthResponse,
|
| 10 |
SessionInfo,
|
| 11 |
SessionResponse,
|
| 12 |
SubmitRequest,
|
| 13 |
)
|
| 14 |
+
from session_manager import session_manager
|
| 15 |
+
from websocket import manager as ws_manager
|
| 16 |
|
| 17 |
logger = logging.getLogger(__name__)
|
| 18 |
|
backend/session_manager.py
CHANGED
|
@@ -11,7 +11,7 @@ from agent.config import load_config
|
|
| 11 |
from agent.core.agent_loop import process_submission
|
| 12 |
from agent.core.session import Event, Operation, OpType, Session, Submission
|
| 13 |
from agent.core.tools import ToolRouter
|
| 14 |
-
from
|
| 15 |
|
| 16 |
logger = logging.getLogger(__name__)
|
| 17 |
|
|
|
|
| 11 |
from agent.core.agent_loop import process_submission
|
| 12 |
from agent.core.session import Event, Operation, OpType, Session, Submission
|
| 13 |
from agent.core.tools import ToolRouter
|
| 14 |
+
from websocket import manager as ws_manager
|
| 15 |
|
| 16 |
logger = logging.getLogger(__name__)
|
| 17 |
|
frontend/package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test_whoosh_search.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Quick manual tester for Whoosh-backed search tools."""
|
| 3 |
+
|
| 4 |
+
import asyncio
|
| 5 |
+
|
| 6 |
+
from agent.tools.docs_tools import explore_hf_docs_handler, search_openapi_handler
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
async def test_docs_search() -> None:
|
| 10 |
+
"""Test HF docs search."""
|
| 11 |
+
print("=" * 60)
|
| 12 |
+
print("Testing explore_hf_docs (optimum, 'chat interface')")
|
| 13 |
+
print("=" * 60)
|
| 14 |
+
result, success = await explore_hf_docs_handler(
|
| 15 |
+
arguments={
|
| 16 |
+
"endpoint": "optimum",
|
| 17 |
+
"query": "chat interface",
|
| 18 |
+
"max_results": 5,
|
| 19 |
+
}
|
| 20 |
+
)
|
| 21 |
+
print(f"Success: {success}")
|
| 22 |
+
print(result[:1000] if len(result) > 1000 else result)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
async def test_api_search() -> None:
|
| 26 |
+
"""Test OpenAPI search."""
|
| 27 |
+
print("\n" + "=" * 60)
|
| 28 |
+
print("Testing find_hf_api ('list user spaces')")
|
| 29 |
+
print("=" * 60)
|
| 30 |
+
result, success = await search_openapi_handler(
|
| 31 |
+
arguments={
|
| 32 |
+
"query": "list user spaces",
|
| 33 |
+
}
|
| 34 |
+
)
|
| 35 |
+
print(f"Success: {success}")
|
| 36 |
+
print(result[:2000] if len(result) > 2000 else result)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
async def test_api_search_with_tag() -> None:
|
| 40 |
+
"""Test OpenAPI search with tag filter."""
|
| 41 |
+
print("\n" + "=" * 60)
|
| 42 |
+
print("Testing find_hf_api ('spaces', tag='spaces')")
|
| 43 |
+
print("=" * 60)
|
| 44 |
+
result, success = await search_openapi_handler(
|
| 45 |
+
arguments={
|
| 46 |
+
"query": "list",
|
| 47 |
+
"tag": "spaces",
|
| 48 |
+
}
|
| 49 |
+
)
|
| 50 |
+
print(f"Success: {success}")
|
| 51 |
+
print(result[:2000] if len(result) > 2000 else result)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def main() -> None:
|
| 55 |
+
# asyncio.run(test_docs_search())
|
| 56 |
+
asyncio.run(test_api_search())
|
| 57 |
+
# asyncio.run(test_api_search_with_tag())
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
main()
|
testing.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
|
| 3 |
+
from agent.tools.dataset_tools import hf_inspect_dataset_handler, inspect_dataset
|
| 4 |
+
from agent.tools.docs_tools import (
|
| 5 |
+
explore_hf_docs_handler,
|
| 6 |
+
hf_docs_fetch_handler,
|
| 7 |
+
search_openapi_handler,
|
| 8 |
+
)
|
| 9 |
+
from agent.tools.github_find_examples import find_examples, github_find_examples_handler
|
| 10 |
+
from agent.tools.github_list_repos import github_list_repos_handler, list_repos
|
| 11 |
+
from agent.tools.github_read_file import github_read_file_handler, read_file
|
| 12 |
+
from agent.tools.hf_repo_files_tool import hf_repo_files_handler
|
| 13 |
+
from agent.tools.hf_repo_git_tool import hf_repo_git_handler
|
| 14 |
+
from agent.tools.jobs_tool import hf_jobs_handler
|
| 15 |
+
from agent.tools.plan_tool import get_current_plan, plan_tool_handler
|
| 16 |
+
from agent.tools.private_hf_repo_tools import private_hf_repo_handler
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Dataset tools
|
| 20 |
+
async def test_inspect_dataset():
|
| 21 |
+
result = await inspect_dataset(dataset="HuggingFaceFW/finetranslations")
|
| 22 |
+
print(result["formatted"], len(result["formatted"]))
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
async def test_hf_inspect_dataset_handler():
|
| 26 |
+
result, success = await hf_inspect_dataset_handler(
|
| 27 |
+
{"dataset": "HuggingFaceFW/finetranslations"}
|
| 28 |
+
)
|
| 29 |
+
print(result, success)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# GitHub tools
|
| 33 |
+
def test_list_repos():
|
| 34 |
+
result = list_repos(owner="huggingface", owner_type="org", sort="stars", limit=5)
|
| 35 |
+
print(result["formatted"], len(result["formatted"]))
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
async def test_github_list_repos_handler():
|
| 39 |
+
result, success = await github_list_repos_handler(
|
| 40 |
+
{"owner": "huggingface", "owner_type": "org", "sort": "stars", "limit": 5}
|
| 41 |
+
)
|
| 42 |
+
print(result, success)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def test_read_file():
|
| 46 |
+
result = read_file(
|
| 47 |
+
repo="huggingface/transformers",
|
| 48 |
+
path="/src/transformers/loss/loss_for_object_detection.py",
|
| 49 |
+
)
|
| 50 |
+
print(result["formatted"], len(result["formatted"]))
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
async def test_github_read_file_handler():
|
| 54 |
+
result, success = await github_read_file_handler(
|
| 55 |
+
{"repo": "huggingface/transformers", "path": "README.md"}
|
| 56 |
+
)
|
| 57 |
+
print(result, success)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def test_find_examples():
|
| 61 |
+
result = find_examples(
|
| 62 |
+
keyword="sft",
|
| 63 |
+
repo="transformers",
|
| 64 |
+
org="huggingface",
|
| 65 |
+
max_results=5,
|
| 66 |
+
min_score=40,
|
| 67 |
+
)
|
| 68 |
+
print(result["formatted"], len(result["formatted"]))
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
async def test_github_find_examples_handler():
|
| 72 |
+
result, success = await github_find_examples_handler(
|
| 73 |
+
{"keyword": "grpo", "repo": "trl", "org": "huggingface", "max_results": 5}
|
| 74 |
+
)
|
| 75 |
+
print(result, success)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
async def test_explore_hf_docs_handler():
|
| 79 |
+
result, success = await explore_hf_docs_handler({"endpoint": "trl"})
|
| 80 |
+
print(result, success)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
async def test_search_openapi_handler():
|
| 84 |
+
result, success = await search_openapi_handler({"tag": "spaces", "query": "logs"})
|
| 85 |
+
print(result, success)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
async def test_hf_docs_fetch_handler():
|
| 89 |
+
result, success = await hf_docs_fetch_handler(
|
| 90 |
+
{"url": "https://huggingface.co/docs/trl/main/en/sft_trainer"}
|
| 91 |
+
)
|
| 92 |
+
print(result, success)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# Jobs tool
|
| 96 |
+
async def test_hf_jobs_handler():
|
| 97 |
+
result, success = await hf_jobs_handler({"operation": "ps"})
|
| 98 |
+
print(result, success)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
# Plan tool
|
| 102 |
+
async def test_plan_tool_handler():
|
| 103 |
+
result, success = await plan_tool_handler(
|
| 104 |
+
{"todos": [{"id": "1", "content": "Test task", "status": "pending"}]}
|
| 105 |
+
)
|
| 106 |
+
print(result, success)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def test_get_current_plan():
|
| 110 |
+
plan = get_current_plan()
|
| 111 |
+
print(plan)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
# Private HF Repo tools
|
| 115 |
+
async def test_private_hf_repo_handler():
|
| 116 |
+
result, success = await private_hf_repo_handler(
|
| 117 |
+
{"operation": "list", "repo_id": "test-repo", "repo_type": "dataset"}
|
| 118 |
+
)
|
| 119 |
+
print(result, success)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
# HF Repo Files tool
|
| 123 |
+
async def test_hf_repo_files_handler():
|
| 124 |
+
result, success = await hf_repo_files_handler(
|
| 125 |
+
{"operation": "list", "repo_id": "bert-base-uncased", "repo_type": "model"}
|
| 126 |
+
)
|
| 127 |
+
print(result, success)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
# HF Repo Git tool
|
| 131 |
+
async def test_hf_repo_git_handler():
|
| 132 |
+
result, success = await hf_repo_git_handler(
|
| 133 |
+
{"operation": "status", "repo_id": "test-repo", "repo_type": "model"}
|
| 134 |
+
)
|
| 135 |
+
print(result, success)
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
if __name__ == "__main__":
|
| 139 |
+
# Uncomment the test you want to run:
|
| 140 |
+
# asyncio.run(test_inspect_dataset())
|
| 141 |
+
# test_list_repos()
|
| 142 |
+
# asyncio.run(test_github_list_repos_handler())
|
| 143 |
+
# test_read_file()
|
| 144 |
+
# asyncio.run(test_github_read_file_handler())
|
| 145 |
+
# test_search_code()
|
| 146 |
+
# asyncio.run(test_github_search_code_handler())
|
| 147 |
+
# test_find_examples()
|
| 148 |
+
# asyncio.run(test_github_find_examples_handler())
|
| 149 |
+
# asyncio.run(test_explore_hf_docs()) # definitely issues
|
| 150 |
+
# asyncio.run(test_explore_hf_docs_handler())
|
| 151 |
+
asyncio.run(test_search_openapi_handler())
|
| 152 |
+
# asyncio.run(test_hf_docs_fetch_handler())
|
| 153 |
+
# asyncio.run(test_hf_jobs_handler())
|
| 154 |
+
# asyncio.run(test_plan_tool_handler())
|
| 155 |
+
# test_get_current_plan()
|
| 156 |
+
# asyncio.run(test_private_hf_repo_handler())
|
| 157 |
+
# asyncio.run(test_hf_repo_files_handler())
|
| 158 |
+
# asyncio.run(test_hf_repo_git_handler())
|