Skip to content

Commit

Permalink
Merge pull request #105 from langchain-ai/mattf/add-langchain_nvidia
Browse files Browse the repository at this point in the history
allow `import langchain_nvidia`
  • Loading branch information
mattf authored Sep 26, 2024
2 parents e3af181 + ab05c3e commit a55975e
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
72 changes: 72 additions & 0 deletions libs/ai-endpoints/langchain_nvidia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""
**LangChain NVIDIA AI Endpoints**
This comprehensive module integrates NVIDIA's state-of-the-art NIM endpoints,
featuring advanced models for conversational AI and semantic embeddings,
into the LangChain framework. It provides robust classes for seamless interaction
with AI models, particularly tailored for enriching conversational experiences
and enhancing semantic understanding in various applications.
**Features:**
1. **`ChatNVIDIA`:** This class serves as the primary interface for interacting
with chat models. Users can effortlessly utilize advanced models like 'Nemotron'
to engage in rich, context-aware conversations, applicable across diverse
domains from customer support to interactive storytelling.
2. **`NVIDIAEmbeddings`:** The class offers capabilities to generate sophisticated
embeddings using AI models. These embeddings are instrumental for tasks like
semantic analysis, text similarity assessments, and contextual understanding,
significantly enhancing the depth of NLP applications.
3. **`NVIDIARerank`:** This class provides an interface for reranking search results
using AI models. Users can leverage this functionality to enhance search
relevance and improve user experience in information retrieval systems.
4. **`NVIDIA`:** This class enables users to interact with large language models
through a completions, or prompting, interface. Users can generate text
completions, summaries, and other language model outputs using this class.
This class is particularly useful for code generation tasks.
**Installation:**
Install this module easily using pip:
```python
pip install langchain-nvidia-ai-endpoints
```
After setting up the environment, interact with NIM endpoints -
## Utilizing chat models:
```python
from langchain_nvidia import ChatNVIDIA
llm = ChatNVIDIA(model="nvidia/llama-3.1-nemotron-51b-instruct")
response = llm.invoke("Tell me about the LangChain integration.")
```
## Generating semantic embeddings:
Create embeddings useful in various NLP tasks:
```python
from langchain_nvidia import NVIDIAEmbeddings
embedder = NVIDIAEmbeddings(model="nvidia/nv-embedqa-e5-v5")
embedding = embedder.embed_query("Exploring AI capabilities.")
```
## Code completion using large language models:
```python
from langchain_nvidia import NVIDIA
llm = NVIDIA(model="meta/codellama-70b")
completion = llm.invoke("def hello_world():")
```
""" # noqa: E501

from langchain_nvidia_ai_endpoints import * # noqa: F403
from langchain_nvidia_ai_endpoints import __all__ # noqa: F401
2 changes: 2 additions & 0 deletions libs/ai-endpoints/langchain_nvidia_ai_endpoints/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""
**NOTE: You can `import langchain_nvidia` instead.**
**LangChain NVIDIA AI Foundation Model Playground Integration**
This comprehensive module integrates NVIDIA's state-of-the-art AI Foundation Models, featuring advanced models for conversational AI and semantic embeddings, into the LangChain framework. It provides robust classes for seamless interaction with NVIDIA's AI models, particularly tailored for enriching conversational experiences and enhancing semantic understanding in various applications.
Expand Down
4 changes: 4 additions & 0 deletions libs/ai-endpoints/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ authors = []
readme = "README.md"
repository = "https://github.com/langchain-ai/langchain-nvidia"
license = "MIT"
packages = [
{ include = "langchain_nvidia.py" },
{ include = "langchain_nvidia_ai_endpoints" },
]

[tool.poetry.urls]
"Source Code" = "https://github.com/langchain-ai/langchain-nvidia/tree/main/libs/ai-endpoints"
Expand Down
6 changes: 4 additions & 2 deletions libs/ai-endpoints/tests/unit_tests/test_imports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from langchain_nvidia_ai_endpoints import __all__
from langchain_nvidia import __all__ as short_all
from langchain_nvidia_ai_endpoints import __all__ as long_all

EXPECTED_ALL = [
"ChatNVIDIA",
Expand All @@ -11,4 +12,5 @@


def test_all_imports() -> None:
assert sorted(EXPECTED_ALL) == sorted(__all__)
assert sorted(EXPECTED_ALL) == sorted(short_all)
assert sorted(EXPECTED_ALL) == sorted(long_all)

0 comments on commit a55975e

Please sign in to comment.