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

Issue with Unexpected 'toolCalls' Property on Chat API in v0.7.8 #244

Closed gregpriday closed 11 months ago

gregpriday commented 11 months ago

Hi there,

I’ve recently updated the openai-php/client from v0.7.5 to v0.7.8 and have run into a snag. When I attempt to use the chat completion endpoint, I'm getting an error regarding an additional 'toolCalls' property not being allowed.

Interestingly, this property was part of the updates introduced in v0.7.7, as per the changelog. However, upon upgrading, my chat functionality is compromised, and an exception is thrown, pointing to this new property as the culprit.

Here's what the error looks like:

OpenAI\Exceptions\ErrorException: Additional properties are not allowed ('toolCalls' was unexpected) - 'messages.2'
/Users/gpriday/Sites/daily-generation/vendor/openai-php/client/src/Transporters/HttpTransporter.php:131
/Users/gpriday/Sites/daily-generation/vendor/openai-php/client/src/Transporters/HttpTransporter.php:57
/Users/gpriday/Sites/daily-generation/vendor/openai-php/client/src/Resources/Chat.php:33
/Users/gpriday/Sites/daily-generation/app/Services/OpenAI/OpenAIPromptService.php:240
/Users/gpriday/Sites/daily-generation/app/Services/OpenAI/OpenAIPromptService.php:55
/Users/gpriday/Sites/daily-generation/app/Services/OpenAI/ProjectQuestionExtractor.php:23
/Users/gpriday/Sites/daily-generation/tests/Unit/Services/ProjectQuestionExtractorTest.php:23
/Users/gpriday/Sites/daily-generation/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:174

For context, the chat feature performs as expected when I’m on v0.7.5, and the issue only appears after the update. To ensure that my project remains functional, I've reverted to v0.7.5 as a temporary measure, which has resolved the error for now. The chat completion call isn't using functions or tools.

Steps to reproduce the problem include upgrading to v0.7.8 and initiating a chat via the API, using the facade from the Laravel package.

Environment:

gehrisandro commented 11 months ago

Hi @gregpriday

I was not able to reproduce the error using the following code:

$result = OpenAI::chat()->create([
            'model' => 'gpt-4-1106-preview',
            'messages' => [
                ['role' => 'user', 'content' => 'What is awesome about PHP?'],
            ],
        ]);

Please provide a full example which reproduces the issue.

gregpriday commented 11 months ago

Sorry! My mistake, it was from the presence of the new toolCalls in the message response that I wasn't properly removing when building up a message history for multi-stage prompts (I was only removing functionCall). Thanks for checking this @gehrisandro, I'll make sure I do more digging before reporting next time.