Skip to content

Commit d67f3ed

Browse files
feat: [google-cloud-modelarmor] A new field filter_config is added to message .google.cloud.modelarmor.v1.SanitizeUserPromptRequest (#13541)
- [ ] Regenerate this pull request now. feat: A new field `filter_config` is added to message `.google.cloud.modelarmor.v1.SanitizeModelResponseRequest PiperOrigin-RevId: 728704493 Source-Link: googleapis/googleapis@d687461 Source-Link: googleapis/googleapis-gen@cf9e7e3 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLW1vZGVsYXJtb3IvLk93bEJvdC55YW1sIiwiaCI6ImNmOWU3ZTM1YTc0MzM3MzBjOTQ1NDMyODVmYTU3N2VlOWE5Yzg0MDYifQ== --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 2913199 commit d67f3ed

File tree

7 files changed

+133
-9
lines changed

7 files changed

+133
-9
lines changed

packages/google-cloud-modelarmor/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ In order to use this library, you first need to go through the following steps:
2626
1. `Select or create a Cloud Platform project.`_
2727
2. `Enable billing for your project.`_
2828
3. `Enable the Model Armor API.`_
29-
4. `Setup Authentication.`_
29+
4. `Set up Authentication.`_
3030

3131
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
3232
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
3333
.. _Enable the Model Armor API.: https://cloud.google.com/security-command-center/docs/model-armor-overview
34-
.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
34+
.. _Set up Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
3535

3636
Installation
3737
~~~~~~~~~~~~

packages/google-cloud-modelarmor/google/cloud/modelarmor/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.1.1" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.1.1" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/types/service.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,13 +901,31 @@ class SdpAdvancedConfig(proto.Message):
901901
class SanitizeUserPromptRequest(proto.Message):
902902
r"""Sanitize User Prompt request.
903903
904+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
905+
904906
Attributes:
905907
name (str):
906908
Required. Represents resource name of
907909
template e.g.
908910
name=projects/sample-project/locations/us-central1/templates/templ01
909911
user_prompt_data (google.cloud.modelarmor_v1.types.DataItem):
910912
Required. User prompt data to sanitize.
913+
filter_config (google.cloud.modelarmor_v1.types.FilterConfig):
914+
Optional. Optional Filter configuration to Sanitize User
915+
Prompt.
916+
917+
If below configuration is specified then Sanitization will
918+
be performed using settings in this configuration along with
919+
settings defined at template level (union of both).
920+
921+
If a filter setting overlaps, then the lowest threshold
922+
value i.e. value with greater false positives will be
923+
applied. For example, the ``filter_configuration`` defines
924+
LOW_AND_ABOVE confidence level for TOXICITY, and template
925+
defines HIGH confidence level, then Sanitization is
926+
performed using LOW_AND_ABOVE confidence level.
927+
928+
This field is a member of `oneof`_ ``_filter_config``.
911929
"""
912930

913931
name: str = proto.Field(
@@ -919,18 +937,41 @@ class SanitizeUserPromptRequest(proto.Message):
919937
number=2,
920938
message="DataItem",
921939
)
940+
filter_config: "FilterConfig" = proto.Field(
941+
proto.MESSAGE,
942+
number=3,
943+
optional=True,
944+
message="FilterConfig",
945+
)
922946

923947

924948
class SanitizeModelResponseRequest(proto.Message):
925949
r"""Sanitize Model Response request.
926950
951+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
952+
927953
Attributes:
928954
name (str):
929955
Required. Represents resource name of
930956
template e.g.
931957
name=projects/sample-project/locations/us-central1/templates/templ01
932958
model_response_data (google.cloud.modelarmor_v1.types.DataItem):
933959
Required. Model response data to sanitize.
960+
filter_config (google.cloud.modelarmor_v1.types.FilterConfig):
961+
Optional. Optional Filter configuration to Sanitize User
962+
Prompt.
963+
964+
If below configuration is specified then Sanitization will
965+
be performed using settings in this configuration along with
966+
settings defined at template level (union of both).
967+
968+
If a filter overlaps, then the highest level of strictness
969+
will be applied. For example, the filter_configuration
970+
specifies LOW_AND_ABOVE confidence level for TOXICITY filter
971+
and template uses HIGH confidence level, then Sanitization
972+
is performed using LOW_AND_ABOVE confidence level.
973+
974+
This field is a member of `oneof`_ ``_filter_config``.
934975
user_prompt (str):
935976
Optional. User Prompt associated with Model
936977
response.
@@ -945,6 +986,12 @@ class SanitizeModelResponseRequest(proto.Message):
945986
number=2,
946987
message="DataItem",
947988
)
989+
filter_config: "FilterConfig" = proto.Field(
990+
proto.MESSAGE,
991+
number=3,
992+
optional=True,
993+
message="FilterConfig",
994+
)
948995
user_prompt: str = proto.Field(
949996
proto.STRING,
950997
number=4,

packages/google-cloud-modelarmor/noxfile.py

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,20 +382,29 @@ def docfx(session):
382382
["python", "upb", "cpp"],
383383
)
384384
def prerelease_deps(session, protobuf_implementation):
385-
"""Run all tests with prerelease versions of dependencies installed."""
385+
"""
386+
Run all tests with pre-release versions of dependencies installed
387+
rather than the standard non pre-release versions.
388+
Pre-releases versions can be installed using
389+
`pip install --pre <package>`.
390+
"""
386391

387392
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"):
388393
session.skip("cpp implementation is not supported in python 3.11+")
389394

390395
# Install all dependencies
391-
session.install("-e", ".[all, tests, tracing]")
396+
session.install("-e", ".")
397+
392398
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
399+
# Install dependencies for the unit test environment
393400
session.install(*unit_deps_all)
401+
394402
system_deps_all = (
395403
SYSTEM_TEST_STANDARD_DEPENDENCIES
396404
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
397405
+ SYSTEM_TEST_EXTRAS
398406
)
407+
# Install dependencies for the system test environment
399408
session.install(*system_deps_all)
400409

401410
# Because we test minimum dependency versions on the minimum Python
@@ -417,6 +426,7 @@ def prerelease_deps(session, protobuf_implementation):
417426
)
418427
]
419428

429+
# Install dependencies specified in `testing/constraints-X.txt`.
420430
session.install(*constraints_deps)
421431

422432
prerel_deps = [
@@ -458,3 +468,70 @@ def prerelease_deps(session, protobuf_implementation):
458468
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
459469
},
460470
)
471+
472+
473+
@nox.session(python="3.13")
474+
@nox.parametrize(
475+
"protobuf_implementation",
476+
["python", "upb"],
477+
)
478+
def core_deps_from_source(session, protobuf_implementation):
479+
"""Run all tests with local versions of core dependencies installed,
480+
rather than pulling core dependencies from PyPI.
481+
"""
482+
483+
# Install all dependencies
484+
session.install(".")
485+
486+
# Install dependencies for the unit test environment
487+
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
488+
session.install(*unit_deps_all)
489+
490+
# Install dependencies for the system test environment
491+
system_deps_all = (
492+
SYSTEM_TEST_STANDARD_DEPENDENCIES
493+
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
494+
+ SYSTEM_TEST_EXTRAS
495+
)
496+
session.install(*system_deps_all)
497+
498+
# Because we test minimum dependency versions on the minimum Python
499+
# version, the first version we test with in the unit tests sessions has a
500+
# constraints file containing all dependencies and extras that should be installed.
501+
with open(
502+
CURRENT_DIRECTORY
503+
/ "testing"
504+
/ f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt",
505+
encoding="utf-8",
506+
) as constraints_file:
507+
constraints_text = constraints_file.read()
508+
509+
# Ignore leading whitespace and comment lines.
510+
constraints_deps = [
511+
match.group(1)
512+
for match in re.finditer(
513+
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
514+
)
515+
]
516+
517+
# Install dependencies specified in `testing/constraints-X.txt`.
518+
session.install(*constraints_deps)
519+
520+
core_dependencies_from_source = [
521+
"google-api-core @ git+https://github.com/googleapis/python-api-core.git",
522+
"google-auth @ git+https://github.com/googleapis/google-auth-library-python.git",
523+
f"{CURRENT_DIRECTORY}/../googleapis-common-protos",
524+
f"{CURRENT_DIRECTORY}/../grpc-google-iam-v1",
525+
"proto-plus @ git+https://github.com/googleapis/proto-plus-python.git",
526+
]
527+
528+
for dep in core_dependencies_from_source:
529+
session.install(dep, "--ignore-installed", "--no-deps")
530+
531+
session.run(
532+
"py.test",
533+
"tests/unit",
534+
env={
535+
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
536+
},
537+
)

packages/google-cloud-modelarmor/samples/generated_samples/snippet_metadata_google.cloud.modelarmor.v1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-modelarmor",
11-
"version": "0.1.1"
11+
"version": "0.1.0"
1212
},
1313
"snippets": [
1414
{

packages/google-cloud-modelarmor/scripts/fixup_modelarmor_v1_keywords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class modelarmorCallTransformer(cst.CSTTransformer):
4444
'get_floor_setting': ('name', ),
4545
'get_template': ('name', ),
4646
'list_templates': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ),
47-
'sanitize_model_response': ('name', 'model_response_data', 'user_prompt', ),
48-
'sanitize_user_prompt': ('name', 'user_prompt_data', ),
47+
'sanitize_model_response': ('name', 'model_response_data', 'filter_config', 'user_prompt', ),
48+
'sanitize_user_prompt': ('name', 'user_prompt_data', 'filter_config', ),
4949
'update_floor_setting': ('floor_setting', 'update_mask', ),
5050
'update_template': ('update_mask', 'template', 'request_id', ),
5151
}

0 commit comments

Comments
 (0)