Skip to content

Commit dfadace

Browse files
sadiqk2OskarStark
authored andcommitted
[Platform][Albert] Improve validation
1 parent 4a6f72b commit dfadace

File tree

6 files changed

+9
-57
lines changed

6 files changed

+9
-57
lines changed

src/platform/src/Bridge/Albert/EmbeddingsModelClient.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\AI\Platform\Bridge\Albert;
1313

1414
use Symfony\AI\Platform\Bridge\OpenAi\Embeddings;
15-
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1615
use Symfony\AI\Platform\Model;
1716
use Symfony\AI\Platform\ModelClientInterface;
1817
use Symfony\AI\Platform\Result\RawHttpResult;
@@ -29,8 +28,6 @@ public function __construct(
2928
#[\SensitiveParameter] private string $apiKey,
3029
private string $baseUrl,
3130
) {
32-
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
33-
'' !== $baseUrl || throw new InvalidArgumentException('The base URL must not be empty.');
3431
}
3532

3633
public function supports(Model $model): bool

src/platform/src/Bridge/Albert/GptModelClient.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\AI\Platform\Bridge\Albert;
1313

1414
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
15-
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1615
use Symfony\AI\Platform\Model;
1716
use Symfony\AI\Platform\ModelClientInterface;
1817
use Symfony\AI\Platform\Result\RawHttpResult;
@@ -33,9 +32,6 @@ public function __construct(
3332
private string $baseUrl,
3433
) {
3534
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
36-
37-
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
38-
'' !== $baseUrl || throw new InvalidArgumentException('The base URL must not be empty.');
3935
}
4036

4137
public function supports(Model $model): bool

src/platform/src/Bridge/Albert/PlatformFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static function create(
3232
str_starts_with($baseUrl, 'https://') || throw new InvalidArgumentException('The Albert URL must start with "https://".');
3333
!str_ends_with($baseUrl, '/') || throw new InvalidArgumentException('The Albert URL must not end with a trailing slash.');
3434
preg_match('/\/v\d+$/', $baseUrl) || throw new InvalidArgumentException('The Albert URL must include an API version (e.g., /v1, /v2).');
35+
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
3536

3637
$httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
3738

src/platform/tests/Bridge/Albert/EmbeddingsModelClientTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,13 @@
1818
use Symfony\AI\Platform\Bridge\Albert\EmbeddingsModelClient;
1919
use Symfony\AI\Platform\Bridge\OpenAi\Embeddings;
2020
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
21-
use Symfony\AI\Platform\Exception\InvalidArgumentException;
2221
use Symfony\Component\HttpClient\MockHttpClient;
2322
use Symfony\Component\HttpClient\Response\JsonMockResponse;
2423

2524
#[CoversClass(EmbeddingsModelClient::class)]
2625
#[Small]
2726
final class EmbeddingsModelClientTest extends TestCase
2827
{
29-
public function testConstructorThrowsExceptionForEmptyApiKey()
30-
{
31-
$this->expectException(InvalidArgumentException::class);
32-
$this->expectExceptionMessage('The API key must not be empty.');
33-
34-
new EmbeddingsModelClient(
35-
new MockHttpClient(),
36-
'',
37-
'https://albert.example.com/'
38-
);
39-
}
40-
41-
public function testConstructorThrowsExceptionForEmptyBaseUrl()
42-
{
43-
$this->expectException(InvalidArgumentException::class);
44-
$this->expectExceptionMessage('The base URL must not be empty.');
45-
46-
new EmbeddingsModelClient(
47-
new MockHttpClient(),
48-
'test-api-key',
49-
''
50-
);
51-
}
52-
5328
public function testSupportsEmbeddingsModel()
5429
{
5530
$client = new EmbeddingsModelClient(

src/platform/tests/Bridge/Albert/GptModelClientTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\AI\Platform\Bridge\Albert\GptModelClient;
1919
use Symfony\AI\Platform\Bridge\OpenAi\Embeddings;
2020
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
21-
use Symfony\AI\Platform\Exception\InvalidArgumentException;
2221
use Symfony\Component\HttpClient\EventSourceHttpClient;
2322
use Symfony\Component\HttpClient\MockHttpClient;
2423
use Symfony\Component\HttpClient\Response\JsonMockResponse;
@@ -27,30 +26,6 @@
2726
#[Small]
2827
final class GptModelClientTest extends TestCase
2928
{
30-
public function testConstructorThrowsExceptionForEmptyApiKey()
31-
{
32-
$this->expectException(InvalidArgumentException::class);
33-
$this->expectExceptionMessage('The API key must not be empty.');
34-
35-
new GptModelClient(
36-
new MockHttpClient(),
37-
'',
38-
'https://albert.example.com/'
39-
);
40-
}
41-
42-
public function testConstructorThrowsExceptionForEmptyBaseUrl()
43-
{
44-
$this->expectException(InvalidArgumentException::class);
45-
$this->expectExceptionMessage('The base URL must not be empty.');
46-
47-
new GptModelClient(
48-
new MockHttpClient(),
49-
'test-api-key',
50-
''
51-
);
52-
}
53-
5429
public function testConstructorWrapsHttpClientInEventSourceHttpClient()
5530
{
5631
self::expectNotToPerformAssertions();

src/platform/tests/Bridge/Albert/PlatformFactoryTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public function testThrowsExceptionForNonHttpsUrl()
5555
PlatformFactory::create('test-key', 'http://albert.example.com');
5656
}
5757

58+
public function testPlatformThrowsExceptionForEmptyApiKey()
59+
{
60+
$this->expectException(InvalidArgumentException::class);
61+
$this->expectExceptionMessage('The API key must not be empty.');
62+
63+
PlatformFactory::create('', 'https://albert.example.com/v2');
64+
}
65+
5866
#[DataProvider('provideUrlsWithTrailingSlash')]
5967
public function testThrowsExceptionForUrlsWithTrailingSlash(string $url)
6068
{

0 commit comments

Comments
 (0)