Skip to content

Add support for NVIDIA NIM as an LLM provider#79

Open
areporeporepo wants to merge 7 commits into
nasa-jpl:mainfrom
areporeporepo:feat/add-nvidia-nim-provider
Open

Add support for NVIDIA NIM as an LLM provider#79
areporeporepo wants to merge 7 commits into
nasa-jpl:mainfrom
areporeporepo:feat/add-nvidia-nim-provider

Conversation

@areporeporepo
Copy link
Copy Markdown

@areporeporepo areporeporepo commented Apr 5, 2026

Adds NVIDIA NIM support. Uses langchain-nvidia-ai-endpoints with ChatNVIDIA. Backwards compatible.

LLM_PROVIDER=nvidia NVIDIA_API_KEY=nvapi-... python turtle_agent.py

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 5, 2026 18:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new LLM provider option (NVIDIA NIM) alongside the existing OpenAI/Anthropic/Ollama support, following the established provider-selection pattern in turtle_agent and updating dependency extras + type hints.

Changes:

  • Extend get_llm() provider switch to support LLM_PROVIDER=nvidia via langchain-nvidia-ai-endpoints / ChatNVIDIA.
  • Update ROSA’s ChatModel type hints to include ChatNVIDIA under TYPE_CHECKING.
  • Add nvidia optional dependency (and include it in the all extra) plus .env template variables for NIM configuration.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/turtle_agent/scripts/llm.py Adds NVIDIA provider branch that constructs ChatNVIDIA using env-based configuration.
src/rosa/rosa.py Extends static type union and docstring to list NVIDIA as a tested provider.
pyproject.toml Adds nvidia extra and includes it in all for optional installs.
.env Documents LLM_PROVIDER=nvidia and adds NVIDIA NIM env var placeholders/defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/turtle_agent/scripts/llm.py Outdated
except ImportError:
raise ImportError(
"langchain-nvidia-ai-endpoints is required for NVIDIA NIM support. "
"Install it with: pip install langchain-nvidia-ai-endpoints"
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ImportError message recommends installing langchain-nvidia-ai-endpoints directly, which can bypass this repo’s pinned/compatible optional dependency set. Prefer pointing users to install the project extra (e.g., pip install 'jpl-rosa[nvidia]' or pip install '.[nvidia]') so they get a known-good version range.

Suggested change
"Install it with: pip install langchain-nvidia-ai-endpoints"
"Install the project's NVIDIA extra with: pip install '.[nvidia]'"

Copilot uses AI. Check for mistakes.
Comment on lines +68 to +70
api_key=get_env_variable("NVIDIA_API_KEY"),
model=os.getenv("NVIDIA_MODEL", "nvidia/nemotron-3-super-120b-a12b"),
base_url=os.getenv("NVIDIA_BASE_URL", "https://integrate.api.nvidia.com/v1"),
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_env_variable() treats an empty string as “set”, and the .env template sets NVIDIA_API_KEY= (empty). With LLM_PROVIDER=nvidia, this will pass an empty API key into ChatNVIDIA and fail later with a less actionable auth error. Consider treating empty/whitespace values as unset (e.g., if not value or not value.strip(): ...) either here or inside get_env_variable() so misconfiguration is caught early with a clear message.

Copilot uses AI. Check for mistakes.
@areporeporepo areporeporepo force-pushed the feat/add-nvidia-nim-provider branch from fb472dc to fdfb51c Compare April 5, 2026 18:38
@areporeporepo areporeporepo requested a review from Copilot April 5, 2026 19:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/turtle_agent/scripts/llm.py Outdated
Comment on lines 108 to 112
value = os.getenv(var_name)
if value is None:
if not value or not value.strip():
msg = f"Environment variable {var_name} is not set."
raise ValueError(msg)
return value
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_env_variable now rejects whitespace-only values (good), but it returns the unstripped value. If an env var has accidental leading/trailing whitespace, this will pass validation but can still cause auth/URL failures downstream. Consider returning value.strip() (and optionally adjusting the error text to say “not set or empty”).

Copilot uses AI. Check for mistakes.
Comment thread src/turtle_agent/scripts/llm.py Outdated
Comment on lines +60 to +66
try:
from langchain_nvidia_ai_endpoints import ChatNVIDIA
except ImportError:
raise ImportError(
"langchain-nvidia-ai-endpoints is required for NVIDIA NIM support. "
"Install the project's NVIDIA extra with: pip install '.[nvidia]'"
)
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When re-raising on failed optional import, consider preserving or suppressing the original exception (except ImportError as e: ... raise ImportError(...) from e or from None). This keeps tracebacks clearer for debugging dependency issues.

Copilot uses AI. Check for mistakes.
anh nguyen and others added 2 commits April 9, 2026 10:18
- Use project extra in ImportError message: pip install 'jpl-rosa[nvidia]'
- Chain ImportError with `from e` for clearer tracebacks
- Return stripped value from get_env_variable() to avoid passing
  whitespace-padded keys to providers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous default (nvidia/nemotron-3-super-120b-a12b) triggers an
AssertionError in langchain-nvidia-ai-endpoints 0.3.x because the NIM
/v1/models API returns duplicate entries for that model. Fixed upstream
in langchain-ai/langchain-nvidia#282 (April 10, 2026) but not yet in a
tagged release (latest v1.2.1 is from March 16, 2026).

Switching the default to llama-3.3-nemotron-super-49b-v1.5:
- In NIM's hardcoded MODEL_TABLE, so avoids the duplicate-candidates path
- Built for agentic AI with native tool-calling (verified)
- NVIDIA + Meta origin, appropriate for NASA/JPL context

NVIDIA_MODEL env var remains configurable for users who want to override
once the upstream fix ships in a released version.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: anh nguyen <anh.nqqq@icloud.com>
@areporeporepo
Copy link
Copy Markdown
Author

Hello @RobRoyce, wondering if Rosa would want to support more open models? Nvidia NIM has a pretty good catalog. There's an upstream bug in langchain-nvidia affecting the newest nemotron-3-super (explained in the commit), but everything else seems to work well from my tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants