Skip to content
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

ErrorException: Undefined array key "choices" #132

Closed
tomirons opened this issue May 31, 2023 · 7 comments · Fixed by #134
Closed

ErrorException: Undefined array key "choices" #132

tomirons opened this issue May 31, 2023 · 7 comments · Fixed by #134

Comments

@tomirons
Copy link

I'm currently using v0.5.2.

When using the chat completions, I keep getting the following exception when there is a server error on OpenAI's side.

CleanShot 2023-05-31 at 10 51 45@2x

While debugging I came across this line.

CleanShot 2023-05-31 at 10 56 51@2x

Why does it check the charset? Is that required?

If I remove the charset part, then the following exception is thrown which I would expect.

CleanShot 2023-05-31 at 11 02 52@2x

@gehrisandro
Copy link
Collaborator

Hi @tomirons

Thank you for raising the issue and your PR.

I made another PR #134 which solves the problem in a more generic way.

Am I right when I assume that the content type is application/json instead of application/json; charset=utf-8. Currently I am not able to reproduce the issue by myself.

@tomirons
Copy link
Author

tomirons commented Jun 1, 2023

@gehrisandro yeah, the content type I've been seeing when debugging this is just application/json.

@yo-mike
Copy link

yo-mike commented Jun 1, 2023

I'm having the same issue today. Thanks for reporting @tomirons.

@duyemura
Copy link

duyemura commented Jun 4, 2023

Hi, I just encountered this when openAI was returning a content_filtered error.
It would be really nice to know if there was an error on the completion call and then what type of error it was.

To help, here's the completion response on this error:
CATEGORY:array(1) { ["error"]=> array(5) { ["message"]=> string(265) "The response was filtered due to the prompt triggering Azure OpenAI’s content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766" ["type"]=> NULL ["param"]=> string(6) "prompt" ["code"]=> string(14) "content_filter" ["status"]=> int(400) } }

@xpethie
Copy link

xpethie commented Jun 7, 2023

I have a similar issue... pls help: got the
ErrorException
Undefined array key "choices"
in prompt

$client = \OpenAI::client(getenv('OPENAI_API_KEY'));
$result_text = $client->completions()->create([
    'model' => 'text-davinci-003',
    'prompt' => 'Analyse this text and give me sentiment of the context on a scale between -1.0 and 1.0 just as decimal without spaces and consider context about Ukraine and Russland or war or death as very negative: ' . $this->article->text,

@gehrisandro
Copy link
Collaborator

This has been fixed in the latest version: 0.5.3

@ondraasek
Copy link

Hi I am using the newest version 0.6.1 and still having this:

[2023-06-17 09:09:12] production.ERROR: Undefined array key "choices" {"exception":"[object] (ErrorException(code: 0): Undefined array key "choices" at /home/forge/app.deeply.cz/vendor/openai-php/client/src/Responses/Chat/CreateStreamedResponse.php:44)
[stacktrace]

any idea? thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants