Skip to content
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
2 changes: 1 addition & 1 deletion docs-snippets-npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"sls": {
"dependencies": {
"com.palantir.foundry.api:api-gateway": {
"minVersion": "1.1590.0",
"minVersion": "1.1593.0",
"maxVersion": "1.x.x",
"optional": false
}
Expand Down
2 changes: 1 addition & 1 deletion foundry_sdk/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# using the autorelease bot
__version__ = "0.0.0"

__openapi_document_version__ = "1.1590.0"
__openapi_document_version__ = "1.1593.0"
2 changes: 2 additions & 0 deletions foundry_sdk/v2/language_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from foundry_sdk.v2.language_models.utils import get_anthropic_base_url
from foundry_sdk.v2.language_models.utils import get_async_http_client
from foundry_sdk.v2.language_models.utils import get_foundry_token
from foundry_sdk.v2.language_models.utils import get_google_base_url
from foundry_sdk.v2.language_models.utils import get_http_client
from foundry_sdk.v2.language_models.utils import get_openai_base_url

Expand All @@ -29,4 +30,5 @@
"get_anthropic_base_url",
"get_http_client",
"get_async_http_client",
"get_google_base_url",
]
22 changes: 22 additions & 0 deletions foundry_sdk/v2/language_models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,28 @@ def get_anthropic_base_url(*, preview: bool = False) -> str:
return f"https://{hostname}/api/v2/llm/proxy/anthropic"


def get_google_base_url(*, preview: bool = False) -> str:
"""Get the Google proxy base URL for use with the google-genai SDK.

Args:
preview: Must be set to True to use this beta feature.

Returns:
The Google proxy base URL for the current Foundry environment.

Raises:
ValueError: If preview is not set to True.
RuntimeError: If the Foundry API gateway base URL is not available in the current context.
"""
if not preview:
raise ValueError(
"get_google_base_url() is in beta. "
"Please set the preview parameter to True to use it."
)
hostname = _get_api_gateway_base_url(preview=True)
return f"https://{hostname}/api/v2/llm/proxy/google"


def get_http_client(*, preview: bool = False, config: Optional[Config] = None) -> HttpClient:
"""Get an HTTP client configured for the current Foundry environment.

Expand Down
21 changes: 21 additions & 0 deletions tests/language_models/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from foundry_sdk.v2.language_models import get_anthropic_base_url
from foundry_sdk.v2.language_models import get_async_http_client
from foundry_sdk.v2.language_models import get_foundry_token
from foundry_sdk.v2.language_models import get_google_base_url
from foundry_sdk.v2.language_models import get_http_client
from foundry_sdk.v2.language_models import get_openai_base_url
from foundry_sdk.v2.language_models.utils import _get_api_gateway_base_url
Expand All @@ -46,6 +47,10 @@ def test_get_anthropic_base_url_requires_preview(self):
with pytest.raises(ValueError, match="preview parameter"):
get_anthropic_base_url()

def test_get_google_base_url_requires_preview(self):
with pytest.raises(ValueError, match="preview parameter"):
get_google_base_url()

def test_get_http_client_requires_preview(self):
with pytest.raises(ValueError, match="preview parameter"):
get_http_client()
Expand Down Expand Up @@ -115,6 +120,22 @@ def test_raises_runtime_error_when_not_in_context(self):
get_anthropic_base_url(preview=True)


class TestGetGoogleBaseUrl:
"""Test get_google_base_url function."""

def test_returns_correct_url(self):
token = HOSTNAME_VAR.set("test.palantirfoundry.com")
try:
result = get_google_base_url(preview=True)
assert result == "https://test.palantirfoundry.com/api/v2/llm/proxy/google"
finally:
HOSTNAME_VAR.reset(token)

def test_raises_runtime_error_when_not_in_context(self):
with pytest.raises(RuntimeError, match="not available"):
get_google_base_url(preview=True)


class TestGetHttpClient:
"""Test get_http_client function."""

Expand Down