Skip to content

Commit d829ca6

Browse files
committed
[OpenAi][ResultConverter] Enhance the exception message if possible
1 parent fb19713 commit d829ca6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/platform/src/Bridge/OpenAI/Embeddings/ResultConverter.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
1515
use Symfony\AI\Platform\Exception\RuntimeException;
1616
use Symfony\AI\Platform\Model;
17+
use Symfony\AI\Platform\ResultConverterInterface;
18+
use Symfony\AI\Platform\Result\RawHttpResult;
1719
use Symfony\AI\Platform\Result\RawResultInterface;
1820
use Symfony\AI\Platform\Result\VectorResult;
19-
use Symfony\AI\Platform\ResultConverterInterface;
2021
use Symfony\AI\Platform\Vector\Vector;
2122

2223
/**
@@ -34,6 +35,14 @@ public function convert(RawResultInterface $result, array $options = []): Vector
3435
$data = $result->getData();
3536

3637
if (!isset($data['data'])) {
38+
if ($result instanceof RawHttpResult) {
39+
throw new RuntimeException(sprintf(
40+
'Response from OpenAI API does not contain "data" key. StatusCode: "%s". Response: %s',
41+
$result->getObject()->getStatusCode(),
42+
json_encode($result->getData(), JSON_THROW_ON_ERROR)
43+
));
44+
}
45+
3746
throw new RuntimeException('Response does not contain data');
3847
}
3948

0 commit comments

Comments
 (0)