Skip to content

Commit 226e394

Browse files
feat: [ModelArmor] add streaming methods StreamSanitizeUserPrompt and StreamSanitizeModelResponse (#9243)
* feat: add streaming methods StreamSanitizeUserPrompt and StreamSanitizeModelResponse feat: add StreamingMode enum and field to sanitize requests PiperOrigin-RevId: 929062585 Source-Link: googleapis/googleapis@591ae02 Source-Link: googleapis/googleapis-gen@96852c2 Copy-Tag: eyJwIjoiTW9kZWxBcm1vci8uT3dsQm90LnlhbWwiLCJoIjoiOTY4NTJjMjEyZDc3ZGI0YWY5OTNmOGQ2Mjk3MDJmN2E2YzUwYjExZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 67c73b3 commit 226e394

14 files changed

Lines changed: 661 additions & 31 deletions

ModelArmor/metadata/V1/Service.php

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/*
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START modelarmor_v1_generated_ModelArmor_StreamSanitizeModelResponse_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\BidiStream;
28+
use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
29+
use Google\Cloud\ModelArmor\V1\DataItem;
30+
use Google\Cloud\ModelArmor\V1\SanitizeModelResponseRequest;
31+
use Google\Cloud\ModelArmor\V1\SanitizeModelResponseResponse;
32+
33+
/**
34+
* Streaming version of Sanitizes Model Response.
35+
*
36+
* @param string $formattedName Represents resource name of template
37+
* e.g. name=projects/sample-project/locations/us-central1/templates/templ01
38+
* Please see {@see ModelArmorClient::templateName()} for help formatting this field.
39+
*/
40+
function stream_sanitize_model_response_sample(string $formattedName): void
41+
{
42+
// Create a client.
43+
$modelArmorClient = new ModelArmorClient();
44+
45+
// Prepare the request message.
46+
$modelResponseData = new DataItem();
47+
$request = (new SanitizeModelResponseRequest())
48+
->setName($formattedName)
49+
->setModelResponseData($modelResponseData);
50+
51+
// Call the API and handle any network failures.
52+
try {
53+
/** @var BidiStream $stream */
54+
$stream = $modelArmorClient->streamSanitizeModelResponse();
55+
$stream->writeAll([$request,]);
56+
57+
/** @var SanitizeModelResponseResponse $element */
58+
foreach ($stream->closeWriteAndReadAll() as $element) {
59+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
60+
}
61+
} catch (ApiException $ex) {
62+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
63+
}
64+
}
65+
66+
/**
67+
* Helper to execute the sample.
68+
*
69+
* This sample has been automatically generated and should be regarded as a code
70+
* template only. It will require modifications to work:
71+
* - It may require correct/in-range values for request initialization.
72+
* - It may require specifying regional endpoints when creating the service client,
73+
* please see the apiEndpoint client configuration option for more details.
74+
*/
75+
function callSample(): void
76+
{
77+
$formattedName = ModelArmorClient::templateName('[PROJECT]', '[LOCATION]', '[TEMPLATE]');
78+
79+
stream_sanitize_model_response_sample($formattedName);
80+
}
81+
// [END modelarmor_v1_generated_ModelArmor_StreamSanitizeModelResponse_sync]
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/*
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START modelarmor_v1_generated_ModelArmor_StreamSanitizeUserPrompt_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\BidiStream;
28+
use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
29+
use Google\Cloud\ModelArmor\V1\DataItem;
30+
use Google\Cloud\ModelArmor\V1\SanitizeUserPromptRequest;
31+
use Google\Cloud\ModelArmor\V1\SanitizeUserPromptResponse;
32+
33+
/**
34+
* Streaming version of Sanitize User Prompt.
35+
*
36+
* @param string $formattedName Represents resource name of template
37+
* e.g. name=projects/sample-project/locations/us-central1/templates/templ01
38+
* Please see {@see ModelArmorClient::templateName()} for help formatting this field.
39+
*/
40+
function stream_sanitize_user_prompt_sample(string $formattedName): void
41+
{
42+
// Create a client.
43+
$modelArmorClient = new ModelArmorClient();
44+
45+
// Prepare the request message.
46+
$userPromptData = new DataItem();
47+
$request = (new SanitizeUserPromptRequest())
48+
->setName($formattedName)
49+
->setUserPromptData($userPromptData);
50+
51+
// Call the API and handle any network failures.
52+
try {
53+
/** @var BidiStream $stream */
54+
$stream = $modelArmorClient->streamSanitizeUserPrompt();
55+
$stream->writeAll([$request,]);
56+
57+
/** @var SanitizeUserPromptResponse $element */
58+
foreach ($stream->closeWriteAndReadAll() as $element) {
59+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
60+
}
61+
} catch (ApiException $ex) {
62+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
63+
}
64+
}
65+
66+
/**
67+
* Helper to execute the sample.
68+
*
69+
* This sample has been automatically generated and should be regarded as a code
70+
* template only. It will require modifications to work:
71+
* - It may require correct/in-range values for request initialization.
72+
* - It may require specifying regional endpoints when creating the service client,
73+
* please see the apiEndpoint client configuration option for more details.
74+
*/
75+
function callSample(): void
76+
{
77+
$formattedName = ModelArmorClient::templateName('[PROJECT]', '[LOCATION]', '[TEMPLATE]');
78+
79+
stream_sanitize_user_prompt_sample($formattedName);
80+
}
81+
// [END modelarmor_v1_generated_ModelArmor_StreamSanitizeUserPrompt_sync]

ModelArmor/samples/V1beta/ModelArmorClient/list_locations.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@
3131

3232
/**
3333
* Lists information about the supported locations for this service.
34-
35-
This method lists locations based on the resource scope provided in
36-
the [ListLocationsRequest.name][google.cloud.location.ListLocationsRequest.name] field: *
37-
**Global locations**: If `name` is empty, the method lists the
38-
public locations available to all projects. * **Project-specific
39-
locations**: If `name` follows the format
40-
`projects/{project}`, the method lists locations visible to that
41-
specific project. This includes public, private, or other
42-
project-specific locations enabled for the project.
43-
44-
For gRPC and client library implementations, the resource name is
45-
passed as the `name` field. For direct service calls, the resource
46-
name is
47-
incorporated into the request path based on the specific service
48-
implementation and version.
34+
*
35+
* This method lists locations based on the resource scope provided in
36+
* the [ListLocationsRequest.name][google.cloud.location.ListLocationsRequest.name] field: *
37+
* **Global locations**: If `name` is empty, the method lists the
38+
* public locations available to all projects. * **Project-specific
39+
* locations**: If `name` follows the format
40+
* `projects/{project}`, the method lists locations visible to that
41+
* specific project. This includes public, private, or other
42+
* project-specific locations enabled for the project.
43+
*
44+
* For gRPC and client library implementations, the resource name is
45+
* passed as the `name` field. For direct service calls, the resource
46+
* name is
47+
* incorporated into the request path based on the specific service
48+
* implementation and version.
4949
*
5050
* This sample has been automatically generated and should be regarded as a code
5151
* template only. It will require modifications to work:

ModelArmor/src/V1/Client/ModelArmorClient.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
namespace Google\Cloud\ModelArmor\V1\Client;
2626

2727
use Google\ApiCore\ApiException;
28+
use Google\ApiCore\BidiStream;
2829
use Google\ApiCore\CredentialsWrapper;
2930
use Google\ApiCore\GapicClientTrait;
3031
use Google\ApiCore\Options\ClientOptions;
@@ -524,6 +525,48 @@ public function sanitizeUserPrompt(
524525
return $this->startApiCall('SanitizeUserPrompt', $request, $callOptions)->wait();
525526
}
526527

528+
/**
529+
* Streaming version of Sanitizes Model Response.
530+
*
531+
* @example samples/V1/ModelArmorClient/stream_sanitize_model_response.php
532+
*
533+
* @param array $callOptions {
534+
* Optional.
535+
*
536+
* @type int $timeoutMillis
537+
* Timeout to use for this call.
538+
* }
539+
*
540+
* @return BidiStream
541+
*
542+
* @throws ApiException Thrown if the API call fails.
543+
*/
544+
public function streamSanitizeModelResponse(array $callOptions = []): BidiStream
545+
{
546+
return $this->startApiCall('StreamSanitizeModelResponse', null, $callOptions);
547+
}
548+
549+
/**
550+
* Streaming version of Sanitize User Prompt.
551+
*
552+
* @example samples/V1/ModelArmorClient/stream_sanitize_user_prompt.php
553+
*
554+
* @param array $callOptions {
555+
* Optional.
556+
*
557+
* @type int $timeoutMillis
558+
* Timeout to use for this call.
559+
* }
560+
*
561+
* @return BidiStream
562+
*
563+
* @throws ApiException Thrown if the API call fails.
564+
*/
565+
public function streamSanitizeUserPrompt(array $callOptions = []): BidiStream
566+
{
567+
return $this->startApiCall('StreamSanitizeUserPrompt', null, $callOptions);
568+
}
569+
527570
/**
528571
* Updates the parameters of a single floor setting of a project
529572
*

ModelArmor/src/V1/SanitizationResult/SanitizationMetadata.php

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ModelArmor/src/V1/SanitizeModelResponseRequest.php

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)