-
-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
PHPStan shows parameter error #78
Comments
You should handle the error messages, but no worries, I already add that handling please check; https://github.com/orhanerday/ChatGPT/blob/b326bbf82299c1267e21cd182c02ea21660fb57f/event-stream.php#L51, $complete = $open_ai->chat($opts, function ($curl_info, $data) use (&$txt) {
if ($obj = json_decode($data) and $obj->error->message != "") {
error_log(json_encode($obj->error->message)); // <- you can bind this message to toastr etc.
} else {
echo $data;
$clean = str_replace("data: ", "", $data);
$arr = json_decode($clean, true);
if ($data != "data: [DONE]\n\n" and isset($arr["choices"][0]["delta"]["content"])) {
$txt .= $arr["choices"][0]["delta"]["content"];
}
}
echo PHP_EOL;
ob_flush();
flush();
return strlen($data);
});
|
Hey 👋 It's not about an error coming in from the API, it's about the type that the method expects as second parameter. The chat method expects a null type as second parameter, but we are giving it a function (closure). |
Did you append ‘"stream" => true,’ to the opts var? $opts = [
'prompt' => "Hello",
'temperature' => 0.9,
"max_tokens" => 150,
"frequency_penalty" => 0,
"presence_penalty" => 0.6,
"stream" => true,
]; |
Yes, I did.
The method
|
Describe the bug
PHPStan shows error:
Parameter #2 $stream of method Orhanerday\OpenAi\OpenAi::chat() expects null, Closure given.
Secondary parameter $stream of chat method is typed null.
To Reproduce
Code snippets
OS
macOS
PHP version
PHP 8.0
Library version
openai V4.7.1
The text was updated successfully, but these errors were encountered: