unconv / google-chat-wtf

an AI chatbot that answers questions based on Google search results
8 stars 3 forks source link

$open_ai_api must not be accessed before initialization #1

Open Muthusi opened 1 year ago

Muthusi commented 1 year ago

Hi first, I like your code very creative and interesting, I am trying to run the code but I have an error I have tried resolving no no avail.

PHP Fatal error: Uncaught Error: Typed property ChatWTF\ChatWTF::$open_ai_api must not be accessed before initialization in /home2/mamamalo/aibuddy.com/test/src/ChatWTF.php:44

Kindly help me sort it out.

unconv commented 1 year ago

Did you modify the original code? That error means the $open_ai_api property is not set when calling the ask() method, but it's set in the constructor so that error should never happen. What PHP version are you using?

Muthusi commented 1 year ago

I did try modifying the code as the initial error was "[30-Jun-2023 08:30:41 UTC] PHP Fatal error: Uncaught Error: Typed property ChatWTF\ChatWTF::$open_ai_api must not be accessed before initialization in /home2/mamamalo/test/src/ChatWTF.php:44 Stack trace:

0 /home2/mamamalo/test/message.php(31): ChatWTF\ChatWTF->ask('ho\n')

1 {main}

thrown in /home2/mamamalo/test/src/ChatWTF.php on line 44) "

I am the thussprime on your youtube video. I had this error initially then tried moving the declaration of the API around to try to resolve it.

unconv commented 1 year ago

Make sure on line 30 in message.php you are passing $openai to GoogleSearchChatWTF. Also check that the constructor of GoogleSearchChatWTF has $open_ai_api as a parameter. The orhanerday/open-ai package should also be installed.