Skip to content

Commit 347a703

Browse files
mikecluckdtmeadows
authored andcommitted
feat(vertex): add support for US multi-region endpoint
* feat: vertex us region * fix lints
1 parent 553ec56 commit 347a703

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/Vertex/Client.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ private function __construct(
5555
);
5656

5757
// @see https://docs.cloud.google.com/vertex-ai/docs/reference/rest#rest_endpoints
58-
$baseUrl = 'https://'.$location.'-aiplatform.googleapis.com';
58+
$baseUrl = match ($location) {
59+
'global' => 'https://aiplatform.googleapis.com',
60+
'us' => 'https://aiplatform.us.rep.googleapis.com',
61+
default => 'https://'.$location.'-aiplatform.googleapis.com',
62+
};
5963

6064
parent::__construct(
6165
headers: [],

tests/Vertex/ClientTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Tests\Vertex;
4+
5+
use Anthropic\Vertex\Client;
6+
use PHPUnit\Framework\TestCase;
7+
8+
/**
9+
* @internal
10+
*
11+
* @coversNothing
12+
*/
13+
class ClientTest extends TestCase
14+
{
15+
/**
16+
* @dataProvider locationBaseUrlProvider
17+
*/
18+
public function testBaseUrlForLocation(string $location, string $expectedHost): void
19+
{
20+
$client = $this->createClientWithLocation($location);
21+
22+
$reflection = new \ReflectionMethod($client, 'getBaseUrl');
23+
$baseUrl = $reflection->invoke($client);
24+
25+
$this->assertInstanceOf(\Psr\Http\Message\UriInterface::class, $baseUrl);
26+
$this->assertSame($expectedHost, (string) $baseUrl);
27+
}
28+
29+
/**
30+
* @return iterable<string, array{string, string}>
31+
*/
32+
public static function locationBaseUrlProvider(): iterable
33+
{
34+
yield 'global region' => ['global', 'https://aiplatform.googleapis.com'];
35+
36+
yield 'us region' => ['us', 'https://aiplatform.us.rep.googleapis.com'];
37+
38+
yield 'us-central1 region' => ['us-central1', 'https://us-central1-aiplatform.googleapis.com'];
39+
40+
yield 'europe-west1 region' => ['europe-west1', 'https://europe-west1-aiplatform.googleapis.com'];
41+
42+
yield 'asia-southeast1 region' => ['asia-southeast1', 'https://asia-southeast1-aiplatform.googleapis.com'];
43+
}
44+
45+
private function createClientWithLocation(string $location): Client
46+
{
47+
$reflection = new \ReflectionClass(Client::class);
48+
$constructor = $reflection->getConstructor();
49+
assert(null !== $constructor);
50+
51+
$client = $reflection->newInstanceWithoutConstructor();
52+
53+
$credentialsProvider = function () {
54+
throw new \RuntimeException('Should not be called in tests');
55+
};
56+
57+
$constructor->invoke($client, $credentialsProvider, $location, 'test-project');
58+
59+
return $client;
60+
}
61+
}

0 commit comments

Comments
 (0)