-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fix crash when quota info is missing from completion response #189
Fix crash when quota info is missing from completion response #189
Conversation
… does not have usage.total_tokens set Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
@@ -324,7 +324,7 @@ public function createCompletion( | |||
throw new Exception($this->l10n->t('Unknown text generation error'), Http::STATUS_INTERNAL_SERVER_ERROR); | |||
} | |||
|
|||
if (isset($response['usage'])) { | |||
if (isset($response['usage'], $response['usage']['total_tokens'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (isset($response['usage'], $response['usage']['total_tokens'])) { | |
if (isset($response['usage']['total_tokens'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be enough, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't trust the behaviour of isset
enough across all Php versions so I prefer to explicitly check each level separately.
But sure, I tried this in a Php console and it worked as expected:
$a = [];
echo $a['one']; // it crashed
echo isset($a['one']) ? 1 : 0; // prints 0
echo isset($a['one']['two']) ? 1 : 0; // does not crash and prints 0
@@ -461,9 +461,8 @@ public function createChatCompletion( | |||
throw new Exception($this->l10n->t('Unknown text generation error'), Http::STATUS_INTERNAL_SERVER_ERROR); | |||
} | |||
|
|||
if (isset($response['usage'])) { | |||
if (isset($response['usage'], $response['usage']['total_tokens'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (isset($response['usage'], $response['usage']['total_tokens'])) { | |
if (isset($response['usage']['total_tokens'])) { |
Do not attempt to update local quota if chat/completion response does not have usage.total_tokens set