Skip to content

Commit e958270

Browse files
authored
refactor: introduce PlatformInterface (#149)
1 parent ef42137 commit e958270

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

src/Bridge/OpenAI/PlatformFactory.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace PhpLlm\LlmChain\Bridge\OpenAI;
66

7-
use PhpLlm\LlmChain\Bridge\OpenAI\Embeddings\ModelClient;
8-
use PhpLlm\LlmChain\Bridge\OpenAI\Embeddings\ResponseConverter;
9-
use PhpLlm\LlmChain\Bridge\OpenAI\GPT\ModelClient as GPTResponseFactory;
7+
use PhpLlm\LlmChain\Bridge\OpenAI\Embeddings\ModelClient as EmbeddingsModelClient;
8+
use PhpLlm\LlmChain\Bridge\OpenAI\Embeddings\ResponseConverter as EmbeddingsResponseConverter;
9+
use PhpLlm\LlmChain\Bridge\OpenAI\GPT\ModelClient as GPTModelClient;
1010
use PhpLlm\LlmChain\Bridge\OpenAI\GPT\ResponseConverter as GPTResponseConverter;
1111
use PhpLlm\LlmChain\Platform;
1212
use Symfony\Component\HttpClient\EventSourceHttpClient;
@@ -18,8 +18,8 @@ public static function create(#[\SensitiveParameter] string $apiKey): Platform
1818
$httpClient = new EventSourceHttpClient();
1919

2020
return new Platform(
21-
[new GPTResponseFactory($httpClient, $apiKey), new ModelClient($httpClient, $apiKey)],
22-
[new GPTResponseConverter(), new ResponseConverter()],
21+
[new GPTModelClient($httpClient, $apiKey), new EmbeddingsModelClient($httpClient, $apiKey)],
22+
[new GPTResponseConverter(), new EmbeddingsResponseConverter()],
2323
);
2424
}
2525
}

src/Chain.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @param OutputProcessor[] $outputProcessor
3434
*/
3535
public function __construct(
36-
private Platform $platform,
36+
private PlatformInterface $platform,
3737
private LanguageModel $llm,
3838
iterable $inputProcessor = [],
3939
iterable $outputProcessor = [],

src/Chain/ToolBox/Tool/SimilaritySearch.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use PhpLlm\LlmChain\Document\Vector;
99
use PhpLlm\LlmChain\Document\VectorDocument;
1010
use PhpLlm\LlmChain\Model\EmbeddingsModel;
11-
use PhpLlm\LlmChain\Platform;
11+
use PhpLlm\LlmChain\PlatformInterface;
1212
use PhpLlm\LlmChain\Store\VectorStoreInterface;
1313

1414
#[AsTool('similarity_search', description: 'Searches for documents similar to a query or sentence.')]
@@ -20,7 +20,7 @@ final class SimilaritySearch
2020
public array $usedDocuments = [];
2121

2222
public function __construct(
23-
private readonly Platform $platform,
23+
private readonly PlatformInterface $platform,
2424
private readonly EmbeddingsModel $embeddings,
2525
private readonly VectorStoreInterface $vectorStore,
2626
) {

src/Embedder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
private ClockInterface $clock;
1919

2020
public function __construct(
21-
private Platform $platform,
21+
private PlatformInterface $platform,
2222
private EmbeddingsModel $embeddings,
2323
private StoreInterface $store,
2424
?ClockInterface $clock = null,

src/Platform.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
1616
use Symfony\Contracts\HttpClient\ResponseInterface as HttpResponse;
1717

18-
final readonly class Platform
18+
final readonly class Platform implements PlatformInterface
1919
{
2020
/**
2121
* @var ModelClient[]
@@ -37,10 +37,6 @@ public function __construct(iterable $modelClients, iterable $responseConverter)
3737
$this->responseConverter = $responseConverter instanceof \Traversable ? iterator_to_array($responseConverter) : $responseConverter;
3838
}
3939

40-
/**
41-
* @param array<mixed>|string|object $input
42-
* @param array<string, mixed> $options
43-
*/
4440
public function request(Model $model, array|string|object $input, array $options = []): ResponseInterface
4541
{
4642
$options = array_merge($model->getOptions(), $options);

src/PlatformInterface.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpLlm\LlmChain;
6+
7+
use PhpLlm\LlmChain\Model\Model;
8+
use PhpLlm\LlmChain\Model\Response\ResponseInterface;
9+
10+
interface PlatformInterface
11+
{
12+
/**
13+
* @param array<mixed>|string|object $input
14+
* @param array<string, mixed> $options
15+
*/
16+
public function request(Model $model, array|string|object $input, array $options = []): ResponseInterface;
17+
}

0 commit comments

Comments
 (0)