File size: 4,046 Bytes
cfcbbc8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
#!/usr/bin/env python3
"""
Script to map all :latest models to their underlying versions.
Usage:
export CBORG_API_KEY=...
python map_latest_models.py
"""
import os
import sys
from openai import OpenAI
def test_model_mapping(client, model_id):
"""Test a model and return the underlying model name."""
try:
response = client.chat.completions.create(
model=model_id,
messages=[{"role": "user", "content": "Hi"}],
max_tokens=5
)
return response.model
except Exception as e:
return f"ERROR: {str(e)[:100]}"
def main():
api_key = os.environ.get('CBORG_API_KEY')
if not api_key:
print("Error: CBORG_API_KEY environment variable not set.")
sys.exit(1)
client = OpenAI(
api_key=api_key,
base_url="https://api.cborg.lbl.gov"
)
# Get all available models
try:
response = client.models.list()
all_models = [model.id for model in response.data]
except Exception as e:
print(f"Error fetching model list: {e}")
sys.exit(1)
# Filter for models with :latest
latest_models = [m for m in all_models if ':latest' in m]
# Also check models without suffix to compare
base_models = []
for latest in latest_models:
base = latest.replace(':latest', '')
if base in all_models:
base_models.append(base)
print("=" * 100)
print("MAPPING OF :latest MODELS TO UNDERLYING VERSIONS")
print("=" * 100)
results = []
# Test :latest models
print(f"\nTesting {len(latest_models)} models with :latest suffix...")
for model in sorted(latest_models):
print(f" Testing {model}...", end=" ", flush=True)
underlying = test_model_mapping(client, model)
results.append((model, underlying))
print("β")
# Test base models for comparison
print(f"\nTesting {len(base_models)} corresponding base models (without :latest)...")
for model in sorted(base_models):
print(f" Testing {model}...", end=" ", flush=True)
underlying = test_model_mapping(client, model)
results.append((model, underlying))
print("β")
# Print results
print("\n" + "=" * 100)
print("RESULTS")
print("=" * 100)
print("\nπ Models with :latest suffix:")
print("-" * 100)
for model, underlying in results:
if ':latest' in model:
if underlying.startswith('ERROR'):
print(f"β {model:<50} {underlying}")
else:
status = "β" if model != underlying else "="
print(f" {model:<50} {status} {underlying}")
print("\nπ Base models (without :latest):")
print("-" * 100)
for model, underlying in results:
if ':latest' not in model:
if underlying.startswith('ERROR'):
print(f"β {model:<50} {underlying}")
else:
status = "β" if model != underlying else "="
print(f" {model:<50} {status} {underlying}")
# Compare :latest vs base
print("\nπ COMPARISON: Do :latest and base versions map to the same model?")
print("-" * 100)
latest_map = {m: u for m, u in results if ':latest' in m}
base_map = {m: u for m, u in results if ':latest' not in m}
for latest, underlying_latest in sorted(latest_map.items()):
base = latest.replace(':latest', '')
if base in base_map:
underlying_base = base_map[base]
if underlying_latest == underlying_base:
print(f"β {latest:<50} SAME as {base}")
print(f" ββ Both map to: {underlying_latest}")
else:
print(f"β οΈ {latest:<50} DIFFERENT from {base}")
print(f" ββ :latest maps to: {underlying_latest}")
print(f" ββ base maps to: {underlying_base}")
print("\n" + "=" * 100)
if __name__ == '__main__':
main()
|