Skip to content

Commit eca9b78

Browse files
committed
feat: add Albert API bridge
- Create dedicated PlatformFactory for Albert API - Handle Albert-specific URL configuration - Add tests for the new bridge - Update documentation to reflect Albert as a separate platform
1 parent f0aec35 commit eca9b78

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ $embeddings = new Embeddings();
6969
* [DeepSeek's R1](https://www.deepseek.com/) with [OpenRouter](https://www.openrouter.com/) as Platform
7070
* [Amazon's Nova](https://nova.amazon.com) with [AWS](https://aws.amazon.com/bedrock/) as Platform
7171
* [Mistral's Mistral](https://www.mistral.ai/) with [Mistral](https://www.mistral.ai/) as Platform
72-
* OpenAI-compatible models via [Albert API](https://github.com/etalab-ia/albert-api) (French government's sovereign AI gateway)
72+
* [Albert API](https://github.com/etalab-ia/albert-api) models with [Albert](https://github.com/etalab-ia/albert-api) as Platform (French government's sovereign AI gateway)
7373
* Embeddings Models
7474
* [OpenAI's Text Embeddings](https://platform.openai.com/docs/guides/embeddings/embedding-models) with [OpenAI](https://platform.openai.com/docs/overview) and [Azure](https://learn.microsoft.com/azure/ai-services/openai/concepts/models) as Platform
7575
* [Voyage's Embeddings](https://docs.voyageai.com/docs/embeddings) with [Voyage](https://www.voyageai.com/) as Platform

examples/albert/chat.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
declare(strict_types=1);
44

55
use PhpLlm\LlmChain\Chain\Chain;
6+
use PhpLlm\LlmChain\Platform\Bridge\Albert\PlatformFactory;
67
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\GPT;
7-
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\PlatformFactory;
88
use PhpLlm\LlmChain\Platform\Message\Message;
99
use PhpLlm\LlmChain\Platform\Message\MessageBag;
1010

@@ -24,9 +24,10 @@
2424
exit(1);
2525
}
2626

27+
// Create platform instance for Albert API
2728
$platform = PlatformFactory::create(
2829
apiKey: $albertApiKey,
29-
baseUrl: rtrim((string) $albertApiUrl, '/').'/v1/',
30+
albertUrl: $albertApiUrl,
3031
);
3132

3233
$model = new GPT('gpt-4o');
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpLlm\LlmChain\Platform\Bridge\Albert;
6+
7+
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Platform;
8+
use Symfony\Component\HttpClient\HttpClient;
9+
use Symfony\Contracts\HttpClient\HttpClientInterface;
10+
11+
final class PlatformFactory
12+
{
13+
/**
14+
* Creates a Platform instance for Albert API.
15+
*/
16+
public static function create(
17+
string $apiKey,
18+
string $albertUrl,
19+
?HttpClientInterface $httpClient = null,
20+
): Platform {
21+
$httpClient ??= HttpClient::create();
22+
23+
return new Platform(
24+
$httpClient,
25+
$apiKey,
26+
rtrim($albertUrl, '/').'/v1/',
27+
);
28+
}
29+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpLlm\LlmChain\Tests\Platform\Bridge\Albert;
6+
7+
use PhpLlm\LlmChain\Platform\Bridge\Albert\PlatformFactory;
8+
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Platform;
9+
use PHPUnit\Framework\Attributes\CoversClass;
10+
use PHPUnit\Framework\Attributes\Small;
11+
use PHPUnit\Framework\Attributes\Test;
12+
use PHPUnit\Framework\TestCase;
13+
14+
#[CoversClass(PlatformFactory::class)]
15+
#[Small]
16+
final class PlatformFactoryTest extends TestCase
17+
{
18+
#[Test]
19+
public function createsPlatformWithCorrectBaseUrl(): void
20+
{
21+
$platform = PlatformFactory::create('test-key', 'https://albert.example.com');
22+
23+
self::assertInstanceOf(Platform::class, $platform);
24+
}
25+
26+
#[Test]
27+
public function trimsTrailingSlashFromUrl(): void
28+
{
29+
$platform1 = PlatformFactory::create('test-key', 'https://albert.example.com/');
30+
$platform2 = PlatformFactory::create('test-key', 'https://albert.example.com');
31+
32+
// Both should create the same platform configuration
33+
self::assertInstanceOf(Platform::class, $platform1);
34+
self::assertInstanceOf(Platform::class, $platform2);
35+
}
36+
}

0 commit comments

Comments
 (0)