treat NotFound specially

This commit is contained in:
Matthew Farrellee 2025-07-16 13:01:24 -04:00
parent 6173d7a308
commit b4ef2599d9

View file

@ -9,7 +9,7 @@ import warnings
from collections.abc import AsyncIterator from collections.abc import AsyncIterator
from typing import Any from typing import Any
from openai import APIConnectionError, AsyncOpenAI, BadRequestError from openai import APIConnectionError, AsyncOpenAI, BadRequestError, NotFoundError
from llama_stack.apis.common.content_types import ( from llama_stack.apis.common.content_types import (
InterleavedContent, InterleavedContent,
@ -89,13 +89,20 @@ class NVIDIAInferenceAdapter(Inference, ModelRegistryHelper):
self._config = config self._config = config
async def check_model_availability(self, model: str) -> bool: async def check_model_availability(self, model: str) -> bool:
"""Check if a specific model is available from the NVIDIA API.""" """
Check if a specific model is available.
:param model: The model identifier to check.
:return: True if the model is available dynamically, False otherwise.
"""
try: try:
await self._get_client().models.retrieve(model) await self._client.models.retrieve(model)
return True return True
except Exception: except NotFoundError:
# If we can't retrieve the model, it's not available logger.error(f"Model {model} is not available")
return False except Exception as e:
logger.error(f"Failed to check model availability: {e}")
return False
@property @property
def _client(self) -> AsyncOpenAI: def _client(self) -> AsyncOpenAI: