Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Bridge/Anthropic/ModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpLlm\LlmChain\Bridge\Anthropic;

use PhpLlm\LlmChain\Exception\RuntimeException;
use PhpLlm\LlmChain\Model\Message\MessageBag;
use PhpLlm\LlmChain\Model\Model;
use PhpLlm\LlmChain\Model\Response\ResponseInterface as LlmResponse;
Expand Down Expand Up @@ -63,6 +64,14 @@ public function convert(ResponseInterface $response, array $options = []): LlmRe

$data = $response->toArray();

if (!isset($data['content']) || 0 === count($data['content'])) {
throw new RuntimeException('Response does not contain any content');
}

if (!isset($data['content'][0]['text'])) {
throw new RuntimeException('Response content does not contain any text');
}

return new TextResponse($data['content'][0]['text']);
}

Expand Down
9 changes: 9 additions & 0 deletions src/Bridge/Ollama/LlamaModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PhpLlm\LlmChain\Bridge\Ollama;

use PhpLlm\LlmChain\Bridge\Meta\Llama;
use PhpLlm\LlmChain\Exception\RuntimeException;
use PhpLlm\LlmChain\Model\Message\MessageBag;
use PhpLlm\LlmChain\Model\Model;
use PhpLlm\LlmChain\Model\Response\ResponseInterface as LlmResponse;
Expand Down Expand Up @@ -43,6 +44,14 @@ public function convert(ResponseInterface $response, array $options = []): LlmRe
{
$data = $response->toArray();

if (!isset($data['message'])) {
throw new RuntimeException('Response does not contain message');
}

if (!isset($data['message']['content'])) {
throw new RuntimeException('Message does not contain content');
}

return new TextResponse($data['message']['content']);
}
}
5 changes: 5 additions & 0 deletions src/Bridge/OpenAI/Embeddings/ResponseConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpLlm\LlmChain\Bridge\OpenAI\Embeddings;
use PhpLlm\LlmChain\Document\Vector;
use PhpLlm\LlmChain\Exception\RuntimeException;
use PhpLlm\LlmChain\Model\Model;
use PhpLlm\LlmChain\Model\Response\VectorResponse;
use PhpLlm\LlmChain\Platform\ResponseConverter as PlatformResponseConverter;
Expand All @@ -22,6 +23,10 @@ public function convert(ResponseInterface $response, array $options = []): Vecto
{
$data = $response->toArray();

if (!isset($data['data'])) {
throw new RuntimeException('Response does not contain data');
}

return new VectorResponse(
...\array_map(
static fn (array $item): Vector => new Vector($item['embedding']),
Expand Down
5 changes: 5 additions & 0 deletions src/Bridge/Replicate/LlamaResponseConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PhpLlm\LlmChain\Bridge\Replicate;

use PhpLlm\LlmChain\Bridge\Meta\Llama;
use PhpLlm\LlmChain\Exception\RuntimeException;
use PhpLlm\LlmChain\Model\Message\MessageBag;
use PhpLlm\LlmChain\Model\Model;
use PhpLlm\LlmChain\Model\Response\ResponseInterface as LlmResponse;
Expand All @@ -23,6 +24,10 @@ public function convert(HttpResponse $response, array $options = []): LlmRespons
{
$data = $response->toArray();

if (!isset($data['output'])) {
throw new RuntimeException('Response does not contain output');
}

return new TextResponse(implode('', $data['output']));
}
}
5 changes: 5 additions & 0 deletions src/Bridge/Voyage/ModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PhpLlm\LlmChain\Bridge\Voyage;

use PhpLlm\LlmChain\Document\Vector;
use PhpLlm\LlmChain\Exception\RuntimeException;
use PhpLlm\LlmChain\Model\Model;
use PhpLlm\LlmChain\Model\Response\ResponseInterface as LlmResponse;
use PhpLlm\LlmChain\Model\Response\VectorResponse;
Expand Down Expand Up @@ -41,6 +42,10 @@ public function convert(ResponseInterface $response, array $options = []): LlmRe
{
$response = $response->toArray();

if (!isset($response['data'])) {
throw new RuntimeException('Response does not contain embedding data');
}

$vectors = array_map(fn (array $data) => new Vector($data['embedding']), $response['data']);

return new VectorResponse($vectors[0]);
Expand Down