Skip to content

[OpenAi][ResultConverter] Enhance the exception message if possible #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Jul 24, 2025

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 { …}
    }
  }

@lyrixx lyrixx force-pushed the openaiexception branch from d829ca6 to a7142fe Compare July 24, 2025 15:25
@chr-hertel
Copy link
Contributor

Yea, the error handling is not great across the entire layer - what do you think about #167?

@chr-hertel chr-hertel added the Platform Issues & PRs about the AI Platform component label Jul 24, 2025
@lyrixx
Copy link
Member Author

lyrixx commented Jul 25, 2025

what do you think about #167?

I think it's better. But, IMHO, it's not enough. Some important information from the raw response (see this PR description) are hidden. They must be shown to the end user to be able to debug easily.

@chr-hertel
Copy link
Contributor

True, we should have as much helpful information as possible.
The challenge here is that - at least ideally - a ResultConverter should not rely on specifics of the used transport (e.g. HTTP) - but maybe that's too far off for now and it's alright to have that dependency for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform Issues & PRs about the AI Platform component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants