|
| 1 | +import pytest |
| 2 | +from test_runner import start_server, stop_server |
| 3 | + |
| 4 | +import requests |
| 5 | +import os |
| 6 | + |
| 7 | +def get_repos_in_collection(collection_id, token): |
| 8 | + # API endpoint to get list of repos in the collection |
| 9 | + url = f"https://huggingface.co/api/collections/{collection_id}" |
| 10 | + headers = {"Authorization": f"Bearer {token}"} |
| 11 | + response = requests.get(url, headers=headers) |
| 12 | + |
| 13 | + # Check response and retrieve repo IDs if successful |
| 14 | + if response.status_code == 200: |
| 15 | + return [repo['id'] for repo in response.json()["items"]] |
| 16 | + else: |
| 17 | + print("Error fetching repos:", response.status_code, response.json()) |
| 18 | + return [] |
| 19 | + |
| 20 | +def get_repo_branches(repo_id, token): |
| 21 | + # API endpoint to get list of branches for each repo |
| 22 | + url = f"https://huggingface.co/api/models/{repo_id}/refs" |
| 23 | + headers = {"Authorization": f"Bearer {token}"} |
| 24 | + response = requests.get(url, headers=headers) |
| 25 | + |
| 26 | + # Check response and get the gguf branch |
| 27 | + if response.status_code == 200: |
| 28 | + branches = response.json()["branches"] |
| 29 | + return [branch['name'] for branch in branches if branch['name'] == 'gguf'] |
| 30 | + else: |
| 31 | + print(f"Error fetching branches for {repo_id}:", response.status_code, response.json()) |
| 32 | + return [] |
| 33 | + |
| 34 | +def get_all_repos_and_default_branches_gguf(collection_id, token): |
| 35 | + # Get list of repos from the collection |
| 36 | + repos = get_repos_in_collection(collection_id, token) |
| 37 | + combined_list = [] |
| 38 | + |
| 39 | + # Iterate over each repo and fetch branches |
| 40 | + for repo_id in repos: |
| 41 | + branches = get_repo_branches(repo_id, token) |
| 42 | + for branch in branches: |
| 43 | + combined_list.append(f"{repo_id.split('/')[1]}:{branch}") |
| 44 | + |
| 45 | + return combined_list |
| 46 | + |
| 47 | +collection_id = "cortexso/local-models-6683a6e29e8f3018845b16db" |
| 48 | +token = os.getenv("HF_TOKEN") |
| 49 | +if not token: |
| 50 | + raise ValueError("HF_TOKEN environment variable not set") |
| 51 | + |
| 52 | +# Call the function and print the results |
| 53 | +repo_branches = get_all_repos_and_default_branches_gguf(collection_id, token) |
| 54 | + |
| 55 | +class TestCortexsoModels: |
| 56 | + |
| 57 | + def setup_and_teardown(self): |
| 58 | + # Setup |
| 59 | + success = start_server() |
| 60 | + if not success: |
| 61 | + raise Exception("Failed to start server") |
| 62 | + yield |
| 63 | + # Teardown |
| 64 | + stop_server() |
| 65 | + |
0 commit comments