Provide default image reponse usage values, if they are not returned by the API#618
Provide default image reponse usage values, if they are not returned by the API#618svendecabooter wants to merge 1 commit intoopenai-php:mainfrom
Conversation
|
You'll find the problem with just adding null checks is the types don't suggest they are null, so it becomes a bit more of a fix to make things nullable as shown by test failures. In this case falling back to a 0 seems misleading, but making them nullable makes downstream users adapt for a nullable case - so a tough call. In this case is a |
|
Hmm I'm not familiar enough with this library or the OpenAI API to know what the best approach would be. Or should we make sure there are always (default) values in the $attributes array earlier on in the code flow? |
|
I'm torn between nullable or
|
Provide default image reponse usage values, if they are not returned by the API (e.g. for LiteLLM)
What:
Description:
We are using LiteLLM as an AI provider. Supposedly this software would provide the same API as OpenAI.
However, we are encountering issues with image response usage statistics.
The PHP client expects various token usage stats to be returned (such as
total_tokens,input_tokens, ...).In our default setup of LiteLLM we only retrieve ["total_tokens" => 0], not the other expected data.
Therefore, it would probably be best not to rely on these values always being there, and providing default values in case they are not, instead of crashing.
Other responses seem to work fine for us for now, but we haven't tested all types yet...