- Strip 'models/' prefix from Google API response for consistency - Model names in .env should be without prefix (e.g., gemini-3.1-pro-preview) - Fixes startup failure when checking model availability Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
22 lines
863 B
Python
22 lines
863 B
Python
from anthropic import AsyncAnthropic
|
|
from openai import AsyncOpenAI
|
|
from google import genai
|
|
|
|
|
|
async def list_available_openai_compatible_models(url: str, api_key: str) -> list[str]:
|
|
client = AsyncOpenAI(api_key=api_key, base_url=url)
|
|
models = (await client.models.list()).data
|
|
if models:
|
|
return list(map(lambda x: x.id, models))
|
|
return []
|
|
|
|
|
|
async def list_available_anthropic_models(api_key: str) -> list[str]:
|
|
client = AsyncAnthropic(api_key=api_key)
|
|
return list(map(lambda x: x.id, (await client.models.list(limit=50)).data))
|
|
|
|
|
|
async def list_available_google_models(api_key: str) -> list[str]:
|
|
client = genai.Client(api_key=api_key)
|
|
# Strip "models/" prefix from model names for consistency with env var format
|
|
return list(map(lambda x: x.name.replace("models/", ""), client.models.list(config={"page_size": 50})))
|