-
-
Notifications
You must be signed in to change notification settings - Fork 509
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
Getting an error when I try to run the chat() method #91
Comments
Please provide more context otherwise I don't know how to help. |
Thank you. Here is my code. I've added all libraries. I have other code snippets working fine like embeddings and completions. For some reason, chat is throwing that error: chat()->create([ 'model' => 'gpt-3.5-turbo', 'messages' => [ ['role' => 'user', 'content' => 'Hello!'], ], ]); $response->id; // 'chatcmpl-6pMyfj1HF4QXnfvjtfzvufZSQq6Eq' $response->object; // 'chat.completion' $response->created; // 1677701073 $response->model; // 'gpt-3.5-turbo-0301' foreach ($response->choices as $result) { $result->index; // 0 $result->message->role; // 'assistant' $result->message->content; // '\n\nHello there! How can I assist you today?' $result->finishReason; // 'stop' } $response->usage->promptTokens; // 9, $response->usage->completionTokens; // 12, $response->usage->totalTokens; // 21 $response->toArray(); // ['id' => 'chatcmpl-6pMyfj1HF4QXnfvjtfzvufZSQq6Eq', ...] |
`<?php require 'vendor/autoload.php'; $client = OpenAI::client('MY_API_KEY'); $response = $client->chat()->create([ $response->id; // 'chatcmpl-6pMyfj1HF4QXnfvjtfzvufZSQq6Eq' foreach ($response->choices as $result) { $response->usage->promptTokens; // 9, $response->toArray(); // ['id' => 'chatcmpl-6pMyfj1HF4QXnfvjtfzvufZSQq6Eq', ...] THrows this error: Fatal error: Uncaught Error: Call to undefined method OpenAI\Client::chat() |
Most likely you are using a package version below v0.3.3 make sure you are using the latest version v0.4.1 |
Thank you. I ran this in my terminal just now: composer require openai-php/client |
Could you please submit the full stacktrace of your exception? |
Fatal error: Uncaught Error: Call to undefined method OpenAI\Client::chat() in /home/.../php-example.php:7 Stack trace: #0 {main} thrown in /home/.../php-example.php on line 7 |
When I copy and paste your code into my application it works fine. |
Thank you. Figured this out. Had to run composer for latest version of openai and your code in the directory where my code was. Had an older version which was working for other methods but not chat. Now working. Thanks. |
Thank you for providing this code. When I try ..., I get this error:
Fatal error: Uncaught Error: Call to undefined method OpenAI\Client::chat()
I've been able to run the code snippets fine as I work down the page. I get this error when I try the chat method. Any suggestions? Thanks!
The text was updated successfully, but these errors were encountered: