File size: 1,815 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 |
#!/usr/bin/env python3
"""
Script to list available CBORG models using your CBORG_API_KEY.
Usage:
export CBORG_API_KEY=...
python list_cborg_models.py
"""
import os
import sys
from openai import OpenAI
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"
)
try:
response = client.models.list()
print("Available CBORG models:")
print("-" * 80)
for model in response.data:
print(f"\nModel ID: {model.id}")
# Try to retrieve detailed information about each model
try:
model_details = client.models.retrieve(model.id)
print(f" Created: {model_details.created if hasattr(model_details, 'created') else 'N/A'}")
print(f" Owned by: {model_details.owned_by if hasattr(model_details, 'owned_by') else 'N/A'}")
# Print all available attributes
print(f" Available attributes:")
for attr in dir(model_details):
if not attr.startswith('_'):
try:
value = getattr(model_details, attr)
if not callable(value):
print(f" {attr}: {value}")
except:
pass
except Exception as e:
print(f" (Could not retrieve detailed info: {e})")
print("-" * 80)
except Exception as e:
print(f"Error fetching model list: {e}")
sys.exit(1)
if __name__ == '__main__':
main()
|