-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from langchain-ai/mattf/patch-1
fix lint and add tests
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
|
||
from langchain_nvidia_ai_endpoints import ChatNVIDIA | ||
|
||
from ..unit_tests.test_api_key import no_env_var | ||
|
||
|
||
def test_missing_api_key_error() -> None: | ||
with no_env_var("NVIDIA_API_KEY"): | ||
chat = ChatNVIDIA() | ||
with pytest.raises(ValueError) as exc_info: | ||
chat.invoke("Hello, world!") | ||
message = str(exc_info.value) | ||
assert "401" in message | ||
assert "Unauthorized" in message | ||
assert "API key" in message | ||
|
||
|
||
def test_bogus_api_key_error() -> None: | ||
with no_env_var("NVIDIA_API_KEY"): | ||
chat = ChatNVIDIA(nvidia_api_key="BOGUS") | ||
with pytest.raises(ValueError) as exc_info: | ||
chat.invoke("Hello, world!") | ||
message = str(exc_info.value) | ||
assert "401" in message | ||
assert "Unauthorized" in message | ||
assert "API key" in message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
from contextlib import contextmanager | ||
from typing import Generator | ||
|
||
from langchain_nvidia_ai_endpoints import ChatNVIDIA, NVIDIAEmbeddings | ||
|
||
|
||
@contextmanager | ||
def no_env_var(var: str) -> Generator[None, None, None]: | ||
try: | ||
if key := os.environ.get(var, None): | ||
del os.environ[var] | ||
yield | ||
finally: | ||
if key: | ||
os.environ[var] = key | ||
|
||
|
||
def test_create_chat_without_api_key() -> None: | ||
with no_env_var("NVIDIA_API_KEY"): | ||
ChatNVIDIA() | ||
|
||
|
||
def test_create_embeddings_without_api_key() -> None: | ||
with no_env_var("NVIDIA_API_KEY"): | ||
NVIDIAEmbeddings() |