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
1 change: 1 addition & 0 deletions agentplatform/_genai/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Any

from google.genai._common import get_value_by_path as getv
from google.genai._transformers import t_content, t_model # noqa: F401

from . import _evals_constant
from . import _evals_data_converters
Expand Down
25 changes: 25 additions & 0 deletions agentplatform/_genai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
from agentplatform._genai import (
serving_profiles as serving_profiles_module,
)
from agentplatform._genai import (
detections as detections_module,
)


_GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules"
Expand Down Expand Up @@ -117,6 +120,7 @@ def __init__(self, api_client: genai_client.BaseApiClient): # type: ignore[name
self._sandboxes: Optional[ModuleType] = None
self._memory_banks: Optional[ModuleType] = None
self._serving_profiles: Optional[ModuleType] = None
self._detections: Optional[ModuleType] = None

@property
@_common.experimental_warning(
Expand Down Expand Up @@ -303,6 +307,17 @@ def serving_profiles(
)
return self._serving_profiles.AsyncServingProfiles(self._api_client) # type: ignore[no-any-return]

@property
def detections(
self,
) -> "detections_module.AsyncDetections":
if self._detections is None:
self._detections = importlib.import_module(
".detections",
__package__,
)
return self._detections.AsyncDetections(self._api_client) # type: ignore[no-any-return]

async def aclose(self) -> None:
"""Closes the async client explicitly.

Expand Down Expand Up @@ -416,6 +431,7 @@ def __init__(
self._sandboxes: Optional[ModuleType] = None
self._memory_banks: Optional[ModuleType] = None
self._serving_profiles: Optional[ModuleType] = None
self._detections: Optional[ModuleType] = None

@property
def evals(self) -> "evals_module.Evals":
Expand Down Expand Up @@ -624,3 +640,12 @@ def serving_profiles(self) -> "serving_profiles_module.ServingProfiles":
__package__,
)
return self._serving_profiles.ServingProfiles(self._api_client) # type: ignore[no-any-return]

@property
def detections(self) -> "detections_module.Detections":
if self._detections is None:
self._detections = importlib.import_module(
".detections",
__package__,
)
return self._detections.Detections(self._api_client) # type: ignore[no-any-return]
214 changes: 214 additions & 0 deletions agentplatform/_genai/detections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Code generated by the Google Gen AI SDK generator DO NOT EDIT.

import json
import logging
from typing import Any, Optional, Union
from urllib.parse import urlencode

from google.genai import _api_module
from google.genai import _common
from google.genai import types as genai_types
from google.genai._api_client import BaseApiClient
from google.genai._common import get_value_by_path as getv
from google.genai._common import set_value_by_path as setv

from . import _transformers as t
from . import types

logger = logging.getLogger("agentplatform_genai.detections")


def _DetectContentParameters_to_vertex(
api_client: BaseApiClient,
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
if getv(from_object, ["model"]) is not None:
setv(
to_object,
["_url", "model"],
t.t_model(api_client, getv(from_object, ["model"])),
)

if getv(from_object, ["content"]) is not None:
setv(to_object, ["content"], t.t_content(getv(from_object, ["content"])))

return to_object


class Detections(_api_module.BaseModule):
"""Class for detecting AI-generated content."""

def detect_content(
self,
*,
model: str,
content: Union[genai_types.ContentUnion, genai_types.ContentUnionDict],
config: Optional[types.DetectContentConfigOrDict] = None,
) -> types.DetectContentResponse:
"""
Detects AI-generated content and C2PA Content Credentials in media inputs.
"""

parameter_model = types._DetectContentParameters(
model=model,
content=content,
config=config,
)

request_url_dict: Optional[dict[str, str]]
if not self._api_client.vertexai:
raise ValueError(
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
)
else:
request_dict = _DetectContentParameters_to_vertex(
self._api_client, parameter_model
)
request_url_dict = request_dict.get("_url")
if request_url_dict:
path = "{model}:detectContent".format_map(request_url_dict)
else:
path = "{model}:detectContent"

query_params = request_dict.get("_query")
if query_params:
path = f"{path}?{urlencode(query_params)}"
# TODO: remove the hack that pops config.
request_dict.pop("config", None)

http_options: Optional[types.HttpOptions] = None
if (
parameter_model.config is not None
and parameter_model.config.http_options is not None
):
http_options = parameter_model.config.http_options

request_dict = _common.convert_to_dict(request_dict)
request_dict = _common.encode_unserializable_types(request_dict)

response = self._api_client.request("post", path, request_dict, http_options)

response_dict = {} if not response.body else json.loads(response.body)

return_value = types.DetectContentResponse._from_response(
response=response_dict,
kwargs=(
{
"config": {
"response_schema": getattr(
parameter_model.config, "response_schema", None
),
"response_json_schema": getattr(
parameter_model.config, "response_json_schema", None
),
"include_all_fields": getattr(
parameter_model.config, "include_all_fields", None
),
}
}
if getattr(parameter_model, "config", None)
else {}
),
)

self._api_client._verify_response(return_value)
return return_value


class AsyncDetections(_api_module.BaseModule):
"""Class for detecting AI-generated content."""

async def detect_content(
self,
*,
model: str,
content: Union[genai_types.ContentUnion, genai_types.ContentUnionDict],
config: Optional[types.DetectContentConfigOrDict] = None,
) -> types.DetectContentResponse:
"""
Detects AI-generated content and C2PA Content Credentials in media inputs.
"""

parameter_model = types._DetectContentParameters(
model=model,
content=content,
config=config,
)

request_url_dict: Optional[dict[str, str]]
if not self._api_client.vertexai:
raise ValueError(
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
)
else:
request_dict = _DetectContentParameters_to_vertex(
self._api_client, parameter_model
)
request_url_dict = request_dict.get("_url")
if request_url_dict:
path = "{model}:detectContent".format_map(request_url_dict)
else:
path = "{model}:detectContent"

query_params = request_dict.get("_query")
if query_params:
path = f"{path}?{urlencode(query_params)}"
# TODO: remove the hack that pops config.
request_dict.pop("config", None)

http_options: Optional[types.HttpOptions] = None
if (
parameter_model.config is not None
and parameter_model.config.http_options is not None
):
http_options = parameter_model.config.http_options

request_dict = _common.convert_to_dict(request_dict)
request_dict = _common.encode_unserializable_types(request_dict)

response = await self._api_client.async_request(
"post", path, request_dict, http_options
)

response_dict = {} if not response.body else json.loads(response.body)

return_value = types.DetectContentResponse._from_response(
response=response_dict,
kwargs=(
{
"config": {
"response_schema": getattr(
parameter_model.config, "response_schema", None
),
"response_json_schema": getattr(
parameter_model.config, "response_json_schema", None
),
"include_all_fields": getattr(
parameter_model.config, "include_all_fields", None
),
}
}
if getattr(parameter_model, "config", None)
else {}
),
)

self._api_client._verify_response(return_value)
return return_value
34 changes: 34 additions & 0 deletions agentplatform/_genai/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from .common import _DeleteServingProfileRequestParameters
from .common import _DeleteSkillRequestParameters
from .common import _DeployRequestParameters
from .common import _DetectContentParameters
from .common import _EvaluateInstancesRequestParameters
from .common import _ExecuteCodeRuntimeSandboxRequestParameters
from .common import _ExportPublisherModelRequestParameters
Expand Down Expand Up @@ -212,6 +213,7 @@
from .common import AggregatedMetricResult
from .common import AggregatedMetricResultDict
from .common import AggregatedMetricResultOrDict
from .common import AiGeneratedLikelihood
from .common import AnalysisConfig
from .common import AnalysisConfigDict
from .common import AnalysisConfigOrDict
Expand Down Expand Up @@ -288,6 +290,15 @@
from .common import BlurBaselineConfig
from .common import BlurBaselineConfigDict
from .common import BlurBaselineConfigOrDict
from .common import C2paResult
from .common import C2paResultDict
from .common import C2paResultManifest
from .common import C2paResultManifestAction
from .common import C2paResultManifestCreationType
from .common import C2paResultManifestDict
from .common import C2paResultManifestOrDict
from .common import C2paResultOrDict
from .common import C2paResultOutcome
from .common import CancelQueryJobResult
from .common import CancelQueryJobResultDict
from .common import CancelQueryJobResultOrDict
Expand Down Expand Up @@ -592,6 +603,12 @@
from .common import DeployResponse
from .common import DeployResponseDict
from .common import DeployResponseOrDict
from .common import DetectContentConfig
from .common import DetectContentConfigDict
from .common import DetectContentConfigOrDict
from .common import DetectContentResponse
from .common import DetectContentResponseDict
from .common import DetectContentResponseOrDict
from .common import DirectUploadSource
from .common import DirectUploadSourceDict
from .common import DirectUploadSourceOrDict
Expand Down Expand Up @@ -4400,6 +4417,18 @@
"GetServingProfileOperationConfig",
"GetServingProfileOperationConfigDict",
"GetServingProfileOperationConfigOrDict",
"DetectContentConfig",
"DetectContentConfigDict",
"DetectContentConfigOrDict",
"C2paResultManifest",
"C2paResultManifestDict",
"C2paResultManifestOrDict",
"C2paResult",
"C2paResultDict",
"C2paResultOrDict",
"DetectContentResponse",
"DetectContentResponseDict",
"DetectContentResponseOrDict",
"PromptOptimizerConfig",
"PromptOptimizerConfigDict",
"PromptOptimizerConfigOrDict",
Expand Down Expand Up @@ -4566,6 +4595,10 @@
"GenerateMemoriesResponseGeneratedMemoryAction",
"RagFileState",
"SkillRevisionState",
"AiGeneratedLikelihood",
"C2paResultOutcome",
"C2paResultManifestCreationType",
"C2paResultManifestAction",
"PromptOptimizerMethod",
"OptimizationMethod",
"PromptData",
Expand Down Expand Up @@ -4764,6 +4797,7 @@
"_ListServingProfilesRequestParameters",
"_DeleteServingProfileRequestParameters",
"_GetServingProfileOperationParameters",
"_DetectContentParameters",
"evals",
"agent_engines",
"prompts",
Expand Down
Loading
Loading