-
Notifications
You must be signed in to change notification settings - Fork 59
Add OCI Generative AI provider codecs and LangChain integration guide #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| --- | ||
| title: "NeMo Relay OCI Generative AI Integration" | ||
| sidebar-title: "OCI Generative AI Integration Guide" | ||
| description: "Add NeMo Relay observability to LangChain agents backed by Oracle Cloud Infrastructure (OCI) Generative AI." | ||
| position: 6 | ||
| --- | ||
| {/* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| SPDX-License-Identifier: Apache-2.0 */} | ||
|
|
||
|
|
||
| Use the `nemo_relay.integrations.langchain` package to add NeMo Relay | ||
| observability to LangChain agents that call | ||
| [Oracle Cloud Infrastructure (OCI) Generative AI](https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/) | ||
| through the [`langchain-oci`](https://pypi.org/project/langchain-oci/) provider. | ||
|
|
||
| OCI Generative AI serves managed on-demand models (Meta Llama, Cohere Command, | ||
| xAI Grok, Google Gemini, and OpenAI models) and dedicated AI cluster endpoints, | ||
| including imported open-weights models such as NVIDIA Nemotron. The same | ||
| integration path covers both. | ||
|
|
||
| ## Setup | ||
|
|
||
| Install the LangChain integration extra together with the OCI provider extra in | ||
| your application environment. | ||
|
|
||
| <Tabs> | ||
| <Tab title="uv"> | ||
| ```bash | ||
| uv add "nemo-relay[langchain,langchain-oci]" | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab title="pip"> | ||
| ```bash | ||
| pip install "nemo-relay[langchain,langchain-oci]" | ||
| ``` | ||
| </Tab> | ||
|
|
||
| </Tabs> | ||
|
|
||
| The `langchain-oci` provider authenticates with the OCI SDK. All standard OCI | ||
| authentication types work: API key, session token, instance principal, and | ||
| resource principal. Configure a profile in `~/.oci/config` or run on an OCI | ||
| compute instance with an instance principal. | ||
|
|
||
| ## Usage Example | ||
|
|
||
| ```python | ||
| import asyncio | ||
|
|
||
| import nemo_relay | ||
| from langchain.agents import create_agent | ||
| from langchain_core.tools import tool | ||
| from langchain_oci import ChatOCIGenAI | ||
| from nemo_relay.integrations.langchain import NemoRelayCallbackHandler, NemoRelayMiddleware | ||
|
|
||
|
|
||
| @tool | ||
| def get_weather(location: str) -> str: | ||
| """Get the current weather for a location.""" | ||
| return f"The weather in {location} is sunny and 72 degrees." | ||
|
|
||
|
|
||
| model = ChatOCIGenAI( | ||
| model_id="meta.llama-3.3-70b-instruct", | ||
| service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com", | ||
| compartment_id="<compartment-ocid>", | ||
| auth_type="API_KEY", | ||
| model_kwargs={"temperature": 0.0, "max_tokens": 512}, | ||
| ) | ||
|
|
||
| agent = create_agent( | ||
| model=model, | ||
| tools=[get_weather], | ||
| middleware=[NemoRelayMiddleware()], | ||
| system_prompt="Use tools when they are relevant. Keep the final answer brief.", | ||
| ) | ||
|
|
||
| input_payload = { | ||
| "messages": [ | ||
| { | ||
| "role": "user", | ||
| "content": "What is the weather in San Francisco?", | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| with nemo_relay.scope.scope("langchain-request", nemo_relay.ScopeType.Agent): | ||
| result = asyncio.run( | ||
| agent.ainvoke(input_payload, config={"callbacks": [NemoRelayCallbackHandler()]}) | ||
| ) | ||
|
|
||
| final_message = result["messages"][-1] | ||
| print(f"Final response: {final_message.content}") | ||
| ``` | ||
|
|
||
| ## Dedicated AI Cluster Endpoints | ||
|
|
||
| To call a model hosted on an OCI dedicated AI cluster — including imported | ||
| open-weights models such as NVIDIA Nemotron — pass the endpoint OCID as the | ||
| model ID. Everything else, including the NeMo Relay integration, stays the | ||
| same: | ||
|
|
||
| ```python | ||
| model = ChatOCIGenAI( | ||
| model_id="ocid1.generativeaiendpoint.oc1.<region>.<endpoint-id>", | ||
| service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com", | ||
| compartment_id="<compartment-ocid>", | ||
| auth_type="API_KEY", | ||
| provider="meta", | ||
| ) | ||
|
Comment on lines
+99
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Locate the relevant docs and implementation.
git ls-files 'docs/supported-integrations/oci-generative-ai.mdx' 'README.md' 'docs/**' 'src/**' 'libs/**' 'packages/**' 2>/dev/null | sed -n '1,200p'
printf '\n--- provider references ---\n'
rg -n 'provider\s*=' docs/supported-integrations/oci-generative-ai.mdx README.md docs src libs packages -g '!**/dist/**' -g '!**/build/**' || true
printf '\n--- ChatOCIGenAI references ---\n'
rg -n 'ChatOCIGenAI|langchain-oci|generic|meta|Nemotron|OCI dedicated AI cluster|generativeaiendpoint' docs src libs packages -g '!**/dist/**' -g '!**/build/**' || trueRepository: NVIDIA/NeMo-Relay Length of output: 26238 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the most relevant file sections with line numbers.
wc -l docs/supported-integrations/oci-generative-ai.mdx
sed -n '80,130p' docs/supported-integrations/oci-generative-ai.mdxRepository: NVIDIA/NeMo-Relay Length of output: 1637 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Read the implementation around the provider argument.
git ls-files | rg 'oci|generativeai|ChatOCIGenAI|langchain-oci' || trueRepository: NVIDIA/NeMo-Relay Length of output: 399 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '90,120p' docs/supported-integrations/oci-generative-ai.mdxRepository: NVIDIA/NeMo-Relay Length of output: 1177 🌐 Web query:
💡 Result: To use an imported NVIDIA Nemotron model on Oracle Cloud Infrastructure (OCI) with LangChain, you should utilize the Citations:
Use 🤖 Prompt for AI AgentsSource: Path instructions |
||
| ``` | ||
|
|
||
| ## Verify the Integration | ||
|
|
||
| The integration works correctly when: | ||
|
|
||
| - The agent run completes and prints a final response. | ||
| - The `langchain-request` scope contains the managed model call. | ||
| - Tool activity appears under the same request when the agent decides to use `get_weather`. | ||
|
|
||
| ## Observability | ||
|
|
||
| Refer to [Observability](/configure-plugins/observability/about) for details on exporting NeMo Relay observability data to third-party systems. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,6 +91,11 @@ langchain-nvidia = [ | |
| "aiohttp>=3.14.1", | ||
| ] | ||
|
|
||
| langchain-oci = [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the need to have this extra. There is no code that depends on the langchain-oci package |
||
| "nemo-relay[langchain]", | ||
| "langchain-oci>=0.2.4,<1.0.0", | ||
| ] | ||
|
|
||
| [tool.maturin] | ||
| manifest-path = "crates/python/Cargo.toml" | ||
| python-source = "python" | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These types of codecs should probably live in the Rust core so any language can leverage it natively. As written, this would only be compatible in Python (which is uneven support and harder to justify). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Provider-specific request and response codecs for ``nemo_relay.llm``. | ||
|
|
||
| Modules in this package implement the ``nemo_relay.codecs.LlmCodec`` and | ||
| ``nemo_relay.codecs.LlmResponseCodec`` protocols for LLM providers whose wire | ||
| formats are not covered by the built-in OpenAI and Anthropic codecs. | ||
| """ | ||
|
|
||
| from nemo_relay.providers.oci_genai import OCIGenAIChatCodec, OCIGenAIResponseCodec | ||
|
|
||
| __all__ = [ | ||
| "OCIGenAIChatCodec", | ||
| "OCIGenAIResponseCodec", | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file makes no reference to the created codecs. I claim that in order for any middleware to function, it would require the Relay library itself to be aware of the created Codecs.
I believe this supports my other comment.