From 4ccf4ef6416e2f1f85ebc1c1736420c4cd865c33 Mon Sep 17 00:00:00 2001 From: Matthew Farrellee Date: Tue, 19 Nov 2024 17:36:08 -0500 Subject: [PATCH] align with other remote adapters, rename config base_url -> url --- llama_stack/providers/remote/inference/nvidia/_config.py | 8 ++++---- llama_stack/providers/remote/inference/nvidia/_nvidia.py | 6 +++--- llama_stack/providers/remote/inference/nvidia/_utils.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/llama_stack/providers/remote/inference/nvidia/_config.py b/llama_stack/providers/remote/inference/nvidia/_config.py index 46ac3fa5b..0b45ecf54 100644 --- a/llama_stack/providers/remote/inference/nvidia/_config.py +++ b/llama_stack/providers/remote/inference/nvidia/_config.py @@ -17,7 +17,7 @@ class NVIDIAConfig(BaseModel): Configuration for the NVIDIA NIM inference endpoint. Attributes: - base_url (str): A base url for accessing the NVIDIA NIM, e.g. http://localhost:8000 + url (str): A base url for accessing the NVIDIA NIM, e.g. http://localhost:8000 api_key (str): The access key for the hosted NIM endpoints There are two ways to access NVIDIA NIMs - @@ -30,11 +30,11 @@ class NVIDIAConfig(BaseModel): By default the configuration will attempt to read the NVIDIA_API_KEY environment variable to set the api_key. Please do not put your API key in code. - If you are using a self-hosted NVIDIA NIM, you can set the base_url to the + If you are using a self-hosted NVIDIA NIM, you can set the url to the URL of your running NVIDIA NIM and do not need to set the api_key. """ - base_url: str = Field( + url: str = Field( default="https://integrate.api.nvidia.com", description="A base url for accessing the NVIDIA NIM", ) @@ -49,4 +49,4 @@ class NVIDIAConfig(BaseModel): @property def is_hosted(self) -> bool: - return "integrate.api.nvidia.com" in self.base_url + return "integrate.api.nvidia.com" in self.url diff --git a/llama_stack/providers/remote/inference/nvidia/_nvidia.py b/llama_stack/providers/remote/inference/nvidia/_nvidia.py index c5bfa0f25..92c4e1cfb 100644 --- a/llama_stack/providers/remote/inference/nvidia/_nvidia.py +++ b/llama_stack/providers/remote/inference/nvidia/_nvidia.py @@ -89,7 +89,7 @@ class NVIDIAInferenceAdapter(Inference, ModelRegistryHelper): # TODO(mf): filter by available models ModelRegistryHelper.__init__(self, model_aliases=_MODEL_ALIASES) - print(f"Initializing NVIDIAInferenceAdapter({config.base_url})...") + print(f"Initializing NVIDIAInferenceAdapter({config.url})...") if config.is_hosted: if not config.api_key: @@ -110,7 +110,7 @@ class NVIDIAInferenceAdapter(Inference, ModelRegistryHelper): self._config = config # make sure the client lives longer than any async calls self._client = AsyncOpenAI( - base_url=f"{self._config.base_url}/v1", + base_url=f"{self._config.url}/v1", api_key=self._config.api_key or "NO KEY", timeout=self._config.timeout, ) @@ -172,7 +172,7 @@ class NVIDIAInferenceAdapter(Inference, ModelRegistryHelper): response = await self._client.chat.completions.create(**request) except APIConnectionError as e: raise ConnectionError( - f"Failed to connect to NVIDIA NIM at {self._config.base_url}: {e}" + f"Failed to connect to NVIDIA NIM at {self._config.url}: {e}" ) from e if stream: diff --git a/llama_stack/providers/remote/inference/nvidia/_utils.py b/llama_stack/providers/remote/inference/nvidia/_utils.py index 6f52bdc4b..c66cf75f4 100644 --- a/llama_stack/providers/remote/inference/nvidia/_utils.py +++ b/llama_stack/providers/remote/inference/nvidia/_utils.py @@ -40,7 +40,7 @@ async def check_health(config: NVIDIAConfig) -> None: if not config.is_hosted: print("Checking NVIDIA NIM health...") try: - is_live, is_ready = await _get_health(config.base_url) + is_live, is_ready = await _get_health(config.url) if not is_live: raise ConnectionError("NVIDIA NIM is not running") if not is_ready: