Skip to content

Added option to skip api url checking. #153

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libs/ai-endpoints/langchain_nvidia_ai_endpoints/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ def _validate_base_url(cls, v: str) -> str:
)

normalized_path = parsed.path.rstrip("/")
if not normalized_path.endswith("/v1"):
skip_api_version_check = os.environ.get(
"NVIDIA_APPEND_API_VERSION", ""
) in ["false", "False", "0"]
if not skip_api_version_check and not normalized_path.endswith("/v1"):
warnings.warn(
f"{v} does not end in /v1, "
"you may have inference and listing issues. "
Expand Down
26 changes: 26 additions & 0 deletions libs/ai-endpoints/tests/unit_tests/test_base_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@ def test_expect_warn(public_class: type, base_url: str) -> None:
assert "does not end in /v1" in str(record[0].message)


@pytest.mark.parametrize(
"base_url",
[
"http://localhost:8888/embeddings",
"http://0.0.0.0:8888/rankings",
"http://localhost:8888/embeddings/",
"http://0.0.0.0:8888/rankings/",
"http://localhost:8888/chat/completions",
"http://localhost:8080/v1/embeddings",
"http://0.0.0.0:8888/v1/rankings",
],
)
def test_expect_skip_check(public_class: type, base_url: str) -> None:
orig = os.environ.get("NVIDIA_APPEND_API_VERSION", None)
warnings.filterwarnings("error")

os.environ["NVIDIA_APPEND_API_VERSION"] = "false"
public_class(model="model1", base_url=base_url)

warnings.resetwarnings()
if orig is None:
del os.environ["NVIDIA_APPEND_API_VERSION"]
else:
os.environ["NVIDIA_APPEND_API_VERSION"] = orig


def test_default_hosted(public_class: type) -> None:
x = public_class(api_key="BOGUS")
assert x._client.is_hosted
Expand Down