Spaces:
Build error
Build error
Download repo_loader.py from mark-ortigas-at-renew/code-analysis: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/mark-ortigas-at-renew/code-analysis/resolve/main/repo_loader.py
- Command line
-
hf download hf://spaces/mark-ortigas-at-renew/code-analysis/repo_loader.py
-
curl -L -o repo_loader.py https://huggingface.co/spaces/mark-ortigas-at-renew/code-analysis/resolve/main/repo_loader.py
1.43 kB
| import pickle | |
| import os | |
| from llama_index import download_loader | |
| from llama_hub.github_repo import GithubClient, GithubRepositoryReader | |
| from github import Github, Auth | |
| def get_docs(owner, repos): | |
| download_loader("GithubRepositoryReader") | |
| all_docs = [] | |
| for repo in repos: | |
| docs = None | |
| file_name = "".join([owner, "-", repo, ".pkl"]) | |
| if os.path.exists(file_name): | |
| with open(file_name, "rb") as f: | |
| docs = pickle.load(f) | |
| if docs is None: | |
| github_client = GithubClient(os.getenv("GITHUB_TOKEN")) | |
| loader = GithubRepositoryReader( | |
| github_client, | |
| owner = owner, | |
| repo = repo, | |
| filter_directories = (["src", "app", "test"], GithubRepositoryReader.FilterType.INCLUDE), | |
| filter_file_extensions = ([".ts"], GithubRepositoryReader.FilterType.INCLUDE), | |
| verbose = True, | |
| concurrent_requests = 10, | |
| ) | |
| docs = loader.load_data(branch="main") | |
| with open(file_name, "wb") as f: | |
| pickle.dump(docs, f) | |
| if docs is not None: | |
| all_docs.extend(docs) | |
| return all_docs | |
| def get_repos(owner): | |
| auth = Auth.Token(os.getenv("GITHUB_TOKEN")) | |
| g = Github(auth=auth) | |
| org = g.get_organization(owner) | |
| repos = org.get_repos() | |
| non_forks = [] | |
| for repo in repos: | |
| if repo.fork is False: | |
| non_forks.append(repo.name) | |
| g.close() | |
| return non_forks |