Team Ai
Apppublic

Thomas636/GithubAgent

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
load_github.py30 linesDownload Raw Back to tools
1from smolagents import Tool2from typing import Any, Optional3 4class SimpleTool(Tool):5    name = "load_github"6    description = "Load a GitHub page and read the README file. Returns the README content."7    inputs = {'github_address': {'type': 'string', 'description': 'a GitHub repository URL (e.g. https://github.com/owner/repo)'}}8    output_type = "string"9 10    def forward(self, github_address: str) -> str:11        """12        Load a GitHub page and read the README file. Returns the README content.13        Args:14            github_address: a GitHub repository URL (e.g. https://github.com/owner/repo)15        """16        import requests  # ✅ Import inside the function so it's captured during serialization17 18        raw_url = github_address.replace("https://github.com/", "https://raw.githubusercontent.com/")19        raw_url = raw_url.rstrip("/") + "/main/README.md"20 21        response = requests.get(raw_url)22 23        if response.status_code == 200:24            return response.text25        else:26            raw_url_master = raw_url.replace("/main/README.md", "/master/README.md")27            response = requests.get(raw_url_master)28            if response.status_code == 200:29                return response.text30            return f"Could not fetch README. Status code: {response.status_code}"