chwellofficial/nt360Slides
0
1import aiohttp2from openai import AsyncOpenAI3from google import genai4 5 6async def list_available_openai_compatible_models(url: str, api_key: str) -> list[str]:7 client = AsyncOpenAI(api_key=api_key, base_url=url)8 models = (await client.models.list()).data9 if models:10 return list(map(lambda x: x.id, models))11 return []12 13 14async def list_available_anthropic_models(api_key: str) -> list[str]:15 async with aiohttp.ClientSession(16 headers={17 "x-api-key": api_key,18 "anthropic-version": "2023-06-01",19 }20 ) as session:21 async with session.get(22 "https://api.anthropic.com/v1/models",23 params={"limit": 50},24 ) as response:25 response.raise_for_status()26 data = await response.json()27 28 models = data.get("data", [])29 return [model.get("id") for model in models if model.get("id")]30 31 32async def list_available_google_models(api_key: str) -> list[str]:33 client = genai.Client(api_key=api_key)34 return list(map(lambda x: x.name, client.models.list(config={"page_size": 50})))35 