File size: 4,938 Bytes
d70b208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import asyncio

from agent.tools.dataset_tools import hf_inspect_dataset_handler, inspect_dataset
from agent.tools.docs_tools import (
    explore_hf_docs_handler,
    hf_docs_fetch_handler,
    search_openapi_handler,
)
from agent.tools.github_find_examples import find_examples, github_find_examples_handler
from agent.tools.github_list_repos import github_list_repos_handler, list_repos
from agent.tools.github_read_file import github_read_file_handler, read_file
from agent.tools.hf_repo_files_tool import hf_repo_files_handler
from agent.tools.hf_repo_git_tool import hf_repo_git_handler
from agent.tools.jobs_tool import hf_jobs_handler
from agent.tools.plan_tool import get_current_plan, plan_tool_handler
from agent.tools.private_hf_repo_tools import private_hf_repo_handler


# Dataset tools
async def test_inspect_dataset():
    result = await inspect_dataset(dataset="HuggingFaceFW/finetranslations")
    print(result["formatted"], len(result["formatted"]))


async def test_hf_inspect_dataset_handler():
    result, success = await hf_inspect_dataset_handler(
        {"dataset": "HuggingFaceFW/finetranslations"}
    )
    print(result, success)


# GitHub tools
def test_list_repos():
    result = list_repos(owner="huggingface", owner_type="org", sort="stars", limit=5)
    print(result["formatted"], len(result["formatted"]))


async def test_github_list_repos_handler():
    result, success = await github_list_repos_handler(
        {"owner": "huggingface", "owner_type": "org", "sort": "stars", "limit": 5}
    )
    print(result, success)


def test_read_file():
    result = read_file(
        repo="huggingface/transformers",
        path="/src/transformers/loss/loss_for_object_detection.py",
    )
    print(result["formatted"], len(result["formatted"]))


async def test_github_read_file_handler():
    result, success = await github_read_file_handler(
        {"repo": "huggingface/transformers", "path": "README.md"}
    )
    print(result, success)


def test_find_examples():
    result = find_examples(
        keyword="sft",
        repo="transformers",
        org="huggingface",
        max_results=5,
        min_score=40,
    )
    print(result["formatted"], len(result["formatted"]))


async def test_github_find_examples_handler():
    result, success = await github_find_examples_handler(
        {"keyword": "grpo", "repo": "trl", "org": "huggingface", "max_results": 5}
    )
    print(result, success)


async def test_explore_hf_docs_handler():
    result, success = await explore_hf_docs_handler({"endpoint": "trl"})
    print(result, success)


async def test_search_openapi_handler():
    result, success = await search_openapi_handler({"tag": "spaces", "query": "logs"})
    print(result, success)


async def test_hf_docs_fetch_handler():
    result, success = await hf_docs_fetch_handler(
        {"url": "https://huggingface.co/docs/trl/main/en/sft_trainer"}
    )
    print(result, success)


# Jobs tool
async def test_hf_jobs_handler():
    result, success = await hf_jobs_handler({"operation": "ps"})
    print(result, success)


# Plan tool
async def test_plan_tool_handler():
    result, success = await plan_tool_handler(
        {"todos": [{"id": "1", "content": "Test task", "status": "pending"}]}
    )
    print(result, success)


def test_get_current_plan():
    plan = get_current_plan()
    print(plan)


# Private HF Repo tools
async def test_private_hf_repo_handler():
    result, success = await private_hf_repo_handler(
        {"operation": "list", "repo_id": "test-repo", "repo_type": "dataset"}
    )
    print(result, success)


# HF Repo Files tool
async def test_hf_repo_files_handler():
    result, success = await hf_repo_files_handler(
        {"operation": "list", "repo_id": "bert-base-uncased", "repo_type": "model"}
    )
    print(result, success)


# HF Repo Git tool
async def test_hf_repo_git_handler():
    result, success = await hf_repo_git_handler(
        {"operation": "status", "repo_id": "test-repo", "repo_type": "model"}
    )
    print(result, success)


if __name__ == "__main__":
    # Uncomment the test you want to run:
    # asyncio.run(test_inspect_dataset())
    # test_list_repos()
    # asyncio.run(test_github_list_repos_handler())
    # test_read_file()
    # asyncio.run(test_github_read_file_handler())
    # test_search_code()
    # asyncio.run(test_github_search_code_handler())
    # test_find_examples()
    # asyncio.run(test_github_find_examples_handler())
    # asyncio.run(test_explore_hf_docs()) # definitely issues
    # asyncio.run(test_explore_hf_docs_handler())
    asyncio.run(test_search_openapi_handler())
    # asyncio.run(test_hf_docs_fetch_handler())
    # asyncio.run(test_hf_jobs_handler())
    # asyncio.run(test_plan_tool_handler())
    # test_get_current_plan()
    # asyncio.run(test_private_hf_repo_handler())
    # asyncio.run(test_hf_repo_files_handler())
    # asyncio.run(test_hf_repo_git_handler())