From dfad6c40a1232aa6163e6ed15a66ce115f8098a0 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Thu, 21 Nov 2024 08:40:45 +0200 Subject: [PATCH] feat: add voyager.ai to supported providers --- src/Provider/Service/Client/VoyagerClient.php | 16 +++++++--------- src/Provider/SupportedProvider.php | 1 + 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Provider/Service/Client/VoyagerClient.php b/src/Provider/Service/Client/VoyagerClient.php index 27f0451..97fda0b 100644 --- a/src/Provider/Service/Client/VoyagerClient.php +++ b/src/Provider/Service/Client/VoyagerClient.php @@ -34,21 +34,19 @@ public function rerank(string $prompt, array $documents, RerankingConfig $config Assert::notEmpty($prompt); Assert::allNotEmpty($documents); - $mapper = function (Document|string $document): string { - if ($document instanceof Document) { - return $document->content; - } - - return $document; - }; - try { /** @var array{results: array} $response */ $response = $this->http->request('POST', 'rerank', [ 'json' => [ 'model' => $config->model, 'top_k' => $config->topK, - 'documents' => array_map($mapper(...), $documents), + 'documents' => array_map( + fn (Document|string $document): string => match (true) { + $document instanceof Document => $document->content, + default => $document, + }, + $documents + ), 'query' => $prompt, ], ])->toArray(); diff --git a/src/Provider/SupportedProvider.php b/src/Provider/SupportedProvider.php index 0a9584d..0bbf3b2 100644 --- a/src/Provider/SupportedProvider.php +++ b/src/Provider/SupportedProvider.php @@ -26,4 +26,5 @@ enum SupportedProvider: string case OLLAMA = 'ollama'; case GITHUB = 'github'; case ANTHROPIC = 'anthropic'; + case VOYAGER = 'voyager'; }