openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.82k stars 499 forks source link

Typo in ThreadRunResponse class: Incorrect Type Definition for $instructions #256

Closed PandaJu closed 10 months ago

PandaJu commented 10 months ago

I hope this message finds you well. I wanted to bring to your attention a small typo in the ThreadRunResponse class in the ThreadRunResponse.php file. It appears that the type definition for the $instructions property is incorrect.

According to the OpenAI API documentation, the $instructions property can be nullable (i.e., it can have a value of null). However, in the ThreadRunResponse class, it is defined as a string type without the nullable annotation.

This typo may lead to a fatal error when the constructor of the ThreadRunResponse class is invoked with a null value for the $instructions parameter.

To resolve this issue and align with the API documentation, I suggest modifying the type declaration for the $instructions property in the ThreadRunResponse class to allow null values. The updated property definition should look like this:

public ?string $instructions,

By making this change, you will ensure that the code handles both string and null values correctly and avoids any potential runtime errors.

Thank you for your attention to this matter. I appreciate your efforts in maintaining the OpenAI PHP client library and ensuring its accuracy.

LMCom commented 10 months ago

Piggybacking here to also point out a typo in some comments that does not justify its own issue. It's "thred" instead of "thread" in four files.

gehrisandro commented 10 months ago

Hi @PandaJu

According to the docs instructions is nullable on the Assistant but not on the ThreadRun. See: https://github.com/openai/openai-openapi/blob/master/openapi.yaml#L8092

Do you have an example request where you get null?

Hi @LMCom

Fixed. Please open a separate issue next time.

PandaJu commented 10 months ago

When creating Assistants using the Assistants feature on the left side of OpenAI, and if the Instructions field is left empty, it will result in the following error: Fatal error: Uncaught TypeError: OpenAI\Responses\Threads\Runs\ThreadRunResponse::__construct(): Argument #15 ($instructions) must be of type string, null given. image

PandaJu commented 10 months ago

I apologize for any confusion caused. Upon reviewing the OpenAI API documentation again, I can confirm that the "instructions" field is indeed optional and can accept a value of null. image

gehrisandro commented 10 months ago

You are right. This is an error in the OpenAI documentation. The field can be null.

I've pushed a fix to the 0.8.x branch and will make a new beta release in a couple of minutes.