|
1 | 1 | import sys |
| 2 | +import concurrent.futures |
2 | 3 | from iclaw.github_api import get_models, get_copilot_token |
3 | 4 | from iclaw.commands.auth import handle_login_command |
| 5 | +from iclaw.commands.test_models import test_model |
4 | 6 |
|
5 | 7 |
|
6 | 8 | def handle_model_provider_command(config_path, current_provider): |
@@ -46,12 +48,29 @@ def handle_model_command(copilot_token, current_model): |
46 | 48 | print(f"Error fetching models: {e}\n", file=sys.stderr) |
47 | 49 | return current_model |
48 | 50 |
|
| 51 | + total = len(model_data) |
| 52 | + print(f"Testing {total} models...") |
| 53 | + with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: |
| 54 | + futures = { |
| 55 | + executor.submit(test_model, copilot_token, m["id"]): m for m in model_data |
| 56 | + } |
| 57 | + working_models = [] |
| 58 | + completed = 0 |
| 59 | + for future in concurrent.futures.as_completed(futures): |
| 60 | + model_id, works = future.result() |
| 61 | + if works: |
| 62 | + working_models.append(futures[future]) |
| 63 | + completed += 1 |
| 64 | + pct = int(completed * 100 / total) |
| 65 | + print(f"\r{pct}% ({completed}/{total})", end="", flush=True) |
| 66 | + print() |
| 67 | + |
49 | 68 | groups = {} |
50 | | - for m in model_data: |
| 69 | + for m in working_models: |
51 | 70 | owner = m.get("owned_by", "unknown") |
52 | 71 | groups.setdefault(owner, []).append(m["id"]) |
53 | 72 |
|
54 | | - flat_models = [m["id"] for m in model_data] |
| 73 | + flat_models = [m["id"] for m in working_models] |
55 | 74 | print(f"\nCurrent model: {current_model}") |
56 | 75 | print("Available models:") |
57 | 76 |
|
|
0 commit comments