Download tools/format_github_repos.py from saishshinde15/GitHub_ToolCallAgent: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/spaces/saishshinde15/GitHub_ToolCallAgent/resolve/main/tools/format_github_repos.py
- Command line
-
hf download hf://spaces/saishshinde15/GitHub_ToolCallAgent/tools/format_github_repos.py
-
curl -L -o format_github_repos.py https://huggingface.co/spaces/saishshinde15/GitHub_ToolCallAgent/resolve/main/tools/format_github_repos.py
2.1 kB
| from smolagents import Tool | |
| from typing import Any, Optional | |
| class SimpleTool(Tool): | |
| name = "format_github_repos" | |
| description = "Formats GitHub repository information into a structured format." | |
| inputs = {"repos":{"type":"object","description":"A dictionary containing a list of repositories under the key \"repos\". Each dictionary inside should have the following keys: - \"name\": The repository name. - \"url\": The GitHub URL. - \"stars\": The number of stars (as a string). - \"description\": A brief description of the repository."}} | |
| output_type = "object" | |
| def forward(self, repos: object) -> object: | |
| """ | |
| Formats GitHub repository information into a structured format. | |
| Args: | |
| repos: A dictionary containing a list of repositories under the key "repos". | |
| Each dictionary inside should have the following keys: | |
| - "name": The repository name. | |
| - "url": The GitHub URL. | |
| - "stars": The number of stars (as a string). | |
| - "description": A brief description of the repository. | |
| Returns: | |
| A structured dictionary containing formatted repository details. | |
| """ | |
| # 🔥 Fix: Unpack if "repos" is nested | |
| if isinstance(repos, dict) and "repos" in repos: | |
| repos = repos["repos"] | |
| if not isinstance(repos, list): | |
| raise ValueError("Expected a list of dictionaries containing repository details.") | |
| required_keys = {"name", "url", "stars", "description"} | |
| formatted_repos = [] | |
| for repo in repos: | |
| if not isinstance(repo, dict) or not required_keys.issubset(repo.keys()): | |
| raise ValueError(f"Each repository dictionary must contain {required_keys}.") | |
| formatted_repos.append({ | |
| "Repository Name": repo["name"], | |
| "URL": repo["url"], | |
| "Stars": repo["stars"], | |
| "Description": repo["description"] | |
| }) | |
| return {"GitHub Repositories": formatted_repos} |