unconv / php-gpt-funcs

GPT-4 Function Calling Example in PHP
30 stars 20 forks source link

Cannot use object of type stdClass as array in C:\xampp82\htdocs\pgf\library\ChatGPT.php:379 #5

Closed D0nVitalio closed 1 day ago

D0nVitalio commented 4 months ago

Hi, Have asked about weather and then wrote "California" and got Cannot use object of type stdClass as array in C:\xampp82\htdocs\pgf\library\ChatGPT.php:379 Quick solved it with if(!is_array($tool_call)){$tool_call = json_decode(json_encode($tool_call), true);} but I think you can solve it better:)

Also right after start, get Undefined array key 1 in C:\xampp82\htdocs\pgf\library\ChatGPT.php on line 582 Solved: if(isset($matches[1])){ $description .= " ".$matches[1]; } else { $description .= " "; }

D0nVitalio commented 4 months ago

And when used php chatbot_with_assistants_api.php What is the weather in California? -> got this: Attempt to read property "type" on array in C:\xampp82\htdocs\pgf\library\ChatGPT.php on line 368 Solved so:

function($tool_call) {
    if(is_array($tool_call)){
        return $tool_call['type'] === "function";
    }else{
        return $tool_call->type === "function";
    }
}

Please correct if needed

unconv commented 1 day ago

It should work now :)