Skip to content

Commit f40fcda

Browse files
committed
minor #199 [OpenAi][ResultConverter] Enhance the exception message if possible (lyrixx)
This PR was merged into the main branch. Discussion ---------- [OpenAi][ResultConverter] Enhance the exception message if possible | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | | Issues | | License | MIT Before: ``` "exception" => Symfony\AI\Platform\Exception\RuntimeException^ {#736 #message: "Response does not contain data" #code: 0 #file: "/home/gregoire/dev/github.com/symfony/ai/src/platform/src/Bridge/OpenAI/Embeddings/ResultConverter.php" #line: 37 trace: { /home/gregoire/dev/github.com/symfony/ai/src/platform/src/Bridge/OpenAI/Embeddings/ResultConverter.php:37 { Symfony\AI\Platform\Bridge\OpenAI\Embeddings\ResultConverter->convert(RawResultInterface $result, array $options = []): VectorResult^ › if (!isset($data['data'])) { › throw new RuntimeException('Response does not contain data'); › } } /home/gregoire/dev/github.com/symfony/ai/src/platform/src/Result/ResultPromise.php:48 { …} /home/gregoire/dev/github.com/symfony/ai/src/platform/src/Result/ResultPromise.php:37 { …} /home/gregoire/dev/github.com/symfony/ai/src/platform/src/Result/ResultPromise.php:111 { …} /home/gregoire/dev/github.com/symfony/ai/src/platform/src/Result/ResultPromise.php:90 { …} ./index.php:181 { …} ./index.php:229 { …} ./index.php:259 { …} } } ``` After ``` "exception" => Symfony\AI\Platform\Exception\RuntimeException^ {#736 #message: "Response from OpenAI API does not contain "data" key. StatusCode: "429". Response: {"error":{"message":"You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https:\/\/platform.openai.com\/docs\/guides\/error-codes\/api-errors.","type":"insufficient_quota","param":null,"code":"insufficient_quota"}}" #code: 0 #file: "/home/gregoire/dev/github.com/symfony/ai/src/platform/src/Bridge/OpenAI/Embeddings/ResultConverter.php" #line: 39 trace: { /home/gregoire/dev/github.com/symfony/ai/src/platform/src/Bridge/OpenAI/Embeddings/ResultConverter.php:39 { Symfony\AI\Platform\Bridge\OpenAI\Embeddings\ResultConverter->convert(RawResultInterface $result, array $options = []): VectorResult^ › if ($result instanceof RawHttpResult) { › throw new RuntimeException(sprintf( › 'Response from OpenAI API does not contain "data" key. StatusCode: "%s". Response: %s', } /home/gregoire/dev/github.com/symfony/ai/src/platform/src/Result/ResultPromise.php:48 { …} /home/gregoire/dev/github.com/symfony/ai/src/platform/src/Result/ResultPromise.php:37 { …} /home/gregoire/dev/github.com/symfony/ai/src/platform/src/Result/ResultPromise.php:111 { …} /home/gregoire/dev/github.com/symfony/ai/src/platform/src/Result/ResultPromise.php:90 { …} ./index.php:181 { …} ./index.php:229 { …} ./index.php:259 { …} } } ``` Commits ------- 39497ea [OpenAi][ResultConverter] Enhance the exception message if possible
2 parents e38cb7f + 39497ea commit f40fcda

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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\Result\RawHttpResult;
1718
use Symfony\AI\Platform\Result\RawResultInterface;
1819
use Symfony\AI\Platform\Result\VectorResult;
1920
use Symfony\AI\Platform\ResultConverterInterface;
@@ -34,6 +35,10 @@ 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('Response from OpenAI API does not contain "data" key. StatusCode: "%s". Response: "%s".', $result->getObject()->getStatusCode(), json_encode($result->getData(), \JSON_THROW_ON_ERROR)));
40+
}
41+
3742
throw new RuntimeException('Response does not contain data.');
3843
}
3944

0 commit comments

Comments
 (0)