Skip to content

Commit c173ddd

Browse files
committed
temporary guard against silent langchain-nvidia failures
Signed-off-by: Bryan Bednarski <bbednarski@nvidia.com>
1 parent 63ce3f0 commit c173ddd

File tree

1 file changed

+18
-7
lines changed
  • packages/nvidia_nat_langchain/src/nat/plugins/langchain

1 file changed

+18
-7
lines changed

packages/nvidia_nat_langchain/src/nat/plugins/langchain/llm.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,30 @@ async def azure_openai_langchain(llm_config: AzureOpenAIModelConfig, _builder: B
169169
async def nim_langchain(llm_config: NIMModelConfig, _builder: Builder):
170170

171171
from langchain_nvidia_ai_endpoints import ChatNVIDIA
172-
from langchain_nvidia_ai_endpoints._statics import MODEL_TABLE, Model
172+
from langchain_nvidia_ai_endpoints import Model
173173

174174
validate_no_responses_api(llm_config, LLMFrameworkEnum.LANGCHAIN)
175175

176+
# TODO: Remove after upgrading to a langchain-nvidia-ai-endpoints release
177+
# that includes https://github.com/langchain-ai/langchain-nvidia/pull/282.
178+
#
176179
# Pre-register unknown models so ChatNVIDIA skips the /v1/models API
177180
# call. This guards against upstream issues such as duplicate entries
178181
# in the API response that cause ChatNVIDIA to crash with AssertionError.
179-
if llm_config.model_name not in MODEL_TABLE:
180-
MODEL_TABLE[llm_config.model_name] = Model(
181-
id=llm_config.model_name,
182-
model_type="chat",
183-
client="ChatNVIDIA",
184-
)
182+
# Uses internal MODEL_TABLE with fallback — if the private module
183+
# changes between langchain-nvidia-ai-endpoints versions, we skip
184+
# pre-registration and let ChatNVIDIA discover the model via /v1/models.
185+
try:
186+
from langchain_nvidia_ai_endpoints._statics import MODEL_TABLE
187+
188+
if llm_config.model_name not in MODEL_TABLE:
189+
MODEL_TABLE[llm_config.model_name] = Model(
190+
id=llm_config.model_name,
191+
model_type="chat",
192+
client="ChatNVIDIA",
193+
)
194+
except (ImportError, AttributeError):
195+
pass
185196

186197
# prefer max_completion_tokens over max_tokens
187198
# verify_ssl is a supported keyword parameter for the ChatNVIDIA client

0 commit comments

Comments
 (0)