Skip to content

Updated warnings for api version check. #150

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

Merged
merged 3 commits into from
Apr 16, 2025
Merged
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
11 changes: 8 additions & 3 deletions libs/ai-endpoints/langchain_nvidia_ai_endpoints/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,18 @@ def _validate_base_url(cls, v: str) -> str:
# Ensure scheme and netloc (domain name) are present
if not (parsed.scheme and parsed.netloc):
expected_format = "Expected format is: http://host:port"
raise ValueError(f"Invalid base_url format. {expected_format} Got: {v}")
warnings.warn(
"The provided url appears incorrect. "
f"Expected: {expected_format} Got: {v}"
)

normalized_path = parsed.path.rstrip("/")
if not normalized_path.endswith("/v1"):
warnings.warn(
f"{v} does not end in /v1, you may "
"have inference and listing issues"
f"{v} does not end in /v1, "
"you may have inference and listing issues. "
"This check will be deprecated in the next release. "
"Please ensure /v1 is appended to the provided URL",
)
normalized_path += "/v1"

Expand Down
10 changes: 5 additions & 5 deletions libs/ai-endpoints/tests/unit_tests/test_base_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def get_base_url(**kwargs: Any) -> str:
"http:/oops",
],
)
def test_param_base_url_negative(public_class: type, base_url: str) -> None:
with no_env_var("NVIDIA_BASE_URL"):
with pytest.raises(ValueError) as e:
public_class(base_url=base_url)
assert "Invalid base_url" in str(e.value)
def test_expect_warn_base_url(public_class: type, base_url: str) -> None:
with pytest.warns(UserWarning) as record:
public_class(model="model1", base_url=base_url)
assert len(record) > 0
assert "url appears incorrect" in str(record[0].message)


@pytest.mark.parametrize(
Expand Down