NVIDIA AI Endpoints for LangChain

1.2.1 · active · verified Sat Apr 11

This integration package connects NVIDIA AI Endpoints with the LangChain framework, providing seamless access to NVIDIA's state-of-the-art AI Foundation Models. It enables robust conversational AI and semantic embedding capabilities through classes like `ChatNVIDIA` and `NVIDIAEmbeddings`. Currently at version 1.2.1, the library maintains an active development pace with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `ChatNVIDIA` for text generation and `NVIDIAEmbeddings` for creating text embeddings. It requires `NVIDIA_API_KEY` to be set as an environment variable, obtainable from the NVIDIA API Catalog. Replace 'nvidia/nemotron-3-super-120b-a12b' and 'nvolveqa_40k' with desired model names available on NVIDIA AI Endpoints.

import os
from langchain_nvidia_ai_endpoints import ChatNVIDIA, NVIDIAEmbeddings

nvapi_key = os.environ.get('NVIDIA_API_KEY', '')
if not nvapi_key.startswith('nvapi-'):
    print("Please set the NVIDIA_API_KEY environment variable. You can get one from the NVIDIA API Catalog.")
else:
    # Initialize ChatNVIDIA for conversational AI
    chat_model = ChatNVIDIA(model="nvidia/nemotron-3-super-120b-a12b", nvidia_api_key=nvapi_key)
    chat_response = chat_model.invoke("Explain the concept of large language models.")
    print("Chat Model Response:", chat_response.content)

    # Initialize NVIDIAEmbeddings for semantic embeddings
    embed_model = NVIDIAEmbeddings(model="nvolveqa_40k", nvidia_api_key=nvapi_key)
    embedding_output = embed_model.embed_query("What are vector embeddings?")
    print("Embedding Model Output Length:", len(embedding_output))

view raw JSON →