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
31 changes: 31 additions & 0 deletions agentplatform/_genai/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,34 @@ def t_inline_results(
api_results.append(api_eval_result)

return api_results


def t_endpoint(endpoint: str) -> str:
if not endpoint:
raise ValueError("endpoint is required.")

# Regex patterns
full_endpoint_pattern = re.compile(
r"^projects/[^/]+/locations/[^/]+/endpoints/[^/]+$"
)
full_publisher_model_pattern = re.compile(
r"^projects/[^/]+/locations/[^/]+/publishers/[^/]+/models/[^/]+$"
)

relative_endpoint_pattern = re.compile(r"^endpoints/[^/]+$")
relative_publisher_model_pattern = re.compile(r"^publishers/[^/]+/models/[^/]+$")

if (
full_endpoint_pattern.match(endpoint)
or full_publisher_model_pattern.match(endpoint)
or relative_endpoint_pattern.match(endpoint)
or relative_publisher_model_pattern.match(endpoint)
):
return endpoint

raise ValueError(
f"Invalid endpoint format: {endpoint}. Must be in the format of"
" projects/.../locations/.../endpoints/... or"
" projects/.../locations/.../publishers/.../models/... or"
" endpoints/... or publishers/.../models/..."
)
23 changes: 23 additions & 0 deletions agentplatform/_genai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
from agentplatform._genai import (
memory_banks as memory_banks_module,
)
from agentplatform._genai import (
endpoints as endpoints_module,
)

_GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules"

Expand Down Expand Up @@ -96,6 +99,7 @@ def __init__(self, api_client: genai_client.BaseApiClient): # type: ignore[name
self._model_garden: Optional[ModuleType] = None
self._feedback_entries: Optional[ModuleType] = None
self._memory_banks: Optional[ModuleType] = None
self._endpoints: Optional[ModuleType] = None

@property
@_common.experimental_warning(
Expand Down Expand Up @@ -186,6 +190,15 @@ def feedback_entries(self) -> "feedback_entries_module.AsyncFeedbackEntries":
)
return self._feedback_entries.AsyncFeedbackEntries(self._api_client) # type: ignore[no-any-return]

@property
def endpoints(self) -> "endpoints_module.AsyncEndpoints":
if self._endpoints is None:
self._endpoints = importlib.import_module(
".endpoints",
__package__,
)
return self._endpoints.AsyncEndpoints(self._api_client) # type: ignore[no-any-return]

@property
@_common.experimental_warning(
"The Vertex SDK GenAI async rag module is experimental, "
Expand Down Expand Up @@ -325,6 +338,7 @@ def __init__(
self._model_garden: Optional[ModuleType] = None
self._feedback_entries: Optional[ModuleType] = None
self._memory_banks: Optional[ModuleType] = None
self._endpoints: Optional[ModuleType] = None

@property
def evals(self) -> "evals_module.Evals":
Expand Down Expand Up @@ -440,6 +454,15 @@ def feedback_entries(self) -> "feedback_entries_module.FeedbackEntries":
)
return self._feedback_entries.FeedbackEntries(self._api_client) # type: ignore[no-any-return]

@property
def endpoints(self) -> "endpoints_module.Endpoints":
if self._endpoints is None:
self._endpoints = importlib.import_module(
".endpoints",
__package__,
)
return self._endpoints.Endpoints(self._api_client) # type: ignore[no-any-return]

@property
@_common.experimental_warning(
"The Vertex SDK GenAI rag module is experimental, "
Expand Down
Loading
Loading