MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / download_github_subdirectory

Function download_github_subdirectory

camel/utils/commons.py:652–694  ·  view source on GitHub ↗

r"""Download subdirectory of the Github repo of the benchmark. This function downloads all files and subdirectories from a specified subdirectory of a GitHub repository and saves them to a local directory. Args: repo (str): The name of the GitHub repository

(
    repo: str, subdir: str, data_dir: Path, branch="main"
)

Source from the content-addressed store, hash-verified

650
651
652def download_github_subdirectory(
653 repo: str, subdir: str, data_dir: Path, branch="main"
654):
655 r"""Download subdirectory of the Github repo of
656 the benchmark.
657
658 This function downloads all files and subdirectories from a
659 specified subdirectory of a GitHub repository and
660 saves them to a local directory.
661
662 Args:
663 repo (str): The name of the GitHub repository
664 in the format "owner/repo".
665 subdir (str): The path to the subdirectory
666 within the repository to download.
667 data_dir (Path): The local directory where
668 the files will be saved.
669 branch (str, optional): The branch of the repository to use.
670 Defaults to "main".
671 """
672 from tqdm import tqdm
673
674 api_url = (
675 f"https://api.github.com/repos/{repo}/contents/{subdir}?ref={branch}"
676 )
677 headers = {"Accept": "application/vnd.github.v3+json"}
678 response = requests.get(api_url, headers=headers)
679 response.raise_for_status()
680 files = response.json()
681 os.makedirs(data_dir, exist_ok=True)
682
683 for file in tqdm(files, desc="Downloading"):
684 file_path = data_dir / file["name"]
685
686 if file["type"] == "file":
687 file_url = file["download_url"]
688 file_response = requests.get(file_url)
689 with open(file_path, "wb") as f:
690 f.write(file_response.content)
691 elif file["type"] == "dir":
692 download_github_subdirectory(
693 repo, f'{subdir}/{file["name"]}', file_path, branch
694 )
695
696
697def generate_prompt_for_structured_output(

Callers 2

downloadMethod · 0.90
downloadMethod · 0.90

Calls 1

jsonMethod · 0.45

Tested by

no test coverage detected