Skip to content

Commit

Permalink
feat: add model and contents fields to ComputeTokensRequest v1 (#7502)
Browse files Browse the repository at this point in the history
feat: add role field to TokensInfo v1
PiperOrigin-RevId: 649172160
Source-Link: googleapis/googleapis@7c0323f
Source-Link: googleapis/googleapis-gen@b8b9681
Copy-Tag: eyJwIjoiQWlQbGF0Zm9ybS8uT3dsQm90LnlhbWwiLCJoIjoiYjhiOTY4MTU5YWY3OWU0MzU5MjEyZmIyYTI3NTFhODA5ODJiNGY5NyJ9
  • Loading branch information
gcf-owl-bot[bot] committed Jul 8, 2024
1 parent 972b114 commit 5ca4b4e
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 26 deletions.
12 changes: 8 additions & 4 deletions AiPlatform/metadata/V1/LlmUtilityService.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Google\Cloud\AIPlatform\V1\Client\LlmUtilityServiceClient;
use Google\Cloud\AIPlatform\V1\ComputeTokensRequest;
use Google\Cloud\AIPlatform\V1\ComputeTokensResponse;
use Google\Protobuf\Value;

/**
* Return a list of tokens based on the input text.
Expand All @@ -42,10 +41,8 @@ function compute_tokens_sample(string $formattedEndpoint): void
$llmUtilityServiceClient = new LlmUtilityServiceClient();

// Prepare the request message.
$instances = [new Value()];
$request = (new ComputeTokensRequest())
->setEndpoint($formattedEndpoint)
->setInstances($instances);
->setEndpoint($formattedEndpoint);

// Call the API and handle any network failures.
try {
Expand Down
92 changes: 84 additions & 8 deletions AiPlatform/src/V1/ComputeTokensRequest.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions AiPlatform/src/V1/TokensInfo.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions AiPlatform/tests/Unit/V1/Client/LlmUtilityServiceClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public function computeTokensTest()
$transport->addResponse($expectedResponse);
// Mock request
$formattedEndpoint = $gapicClient->endpointName('[PROJECT]', '[LOCATION]', '[ENDPOINT]');
$instances = [];
$request = (new ComputeTokensRequest())->setEndpoint($formattedEndpoint)->setInstances($instances);
$request = (new ComputeTokensRequest())->setEndpoint($formattedEndpoint);
$response = $gapicClient->computeTokens($request);
$this->assertEquals($expectedResponse, $response);
$actualRequests = $transport->popReceivedCalls();
Expand All @@ -97,8 +96,6 @@ public function computeTokensTest()
$this->assertSame('/google.cloud.aiplatform.v1.LlmUtilityService/ComputeTokens', $actualFuncCall);
$actualValue = $actualRequestObject->getEndpoint();
$this->assertProtobufEquals($formattedEndpoint, $actualValue);
$actualValue = $actualRequestObject->getInstances();
$this->assertProtobufEquals($instances, $actualValue);
$this->assertTrue($transport->isExhausted());
}

Expand All @@ -125,8 +122,7 @@ public function computeTokensExceptionTest()
$transport->addResponse(null, $status);
// Mock request
$formattedEndpoint = $gapicClient->endpointName('[PROJECT]', '[LOCATION]', '[ENDPOINT]');
$instances = [];
$request = (new ComputeTokensRequest())->setEndpoint($formattedEndpoint)->setInstances($instances);
$request = (new ComputeTokensRequest())->setEndpoint($formattedEndpoint);
try {
$gapicClient->computeTokens($request);
// If the $gapicClient method call did not throw, fail the test
Expand Down Expand Up @@ -573,8 +569,7 @@ public function computeTokensAsyncTest()
$transport->addResponse($expectedResponse);
// Mock request
$formattedEndpoint = $gapicClient->endpointName('[PROJECT]', '[LOCATION]', '[ENDPOINT]');
$instances = [];
$request = (new ComputeTokensRequest())->setEndpoint($formattedEndpoint)->setInstances($instances);
$request = (new ComputeTokensRequest())->setEndpoint($formattedEndpoint);
$response = $gapicClient->computeTokensAsync($request)->wait();
$this->assertEquals($expectedResponse, $response);
$actualRequests = $transport->popReceivedCalls();
Expand All @@ -584,8 +579,6 @@ public function computeTokensAsyncTest()
$this->assertSame('/google.cloud.aiplatform.v1.LlmUtilityService/ComputeTokens', $actualFuncCall);
$actualValue = $actualRequestObject->getEndpoint();
$this->assertProtobufEquals($formattedEndpoint, $actualValue);
$actualValue = $actualRequestObject->getInstances();
$this->assertProtobufEquals($instances, $actualValue);
$this->assertTrue($transport->isExhausted());
}
}

0 comments on commit 5ca4b4e

Please sign in to comment.