More options in postData
oleteacher opened this issue · comments
Hello again. Looking forward to trying out your code in the classroom. Going to teach students proper way to use AI:)
Is there any reason the code below would not work:
$postData = [
"model" => "gpt-3.5-turbo",
"messages" => [],
'max_tokens' => 1000,
'temperature' => 0.7,
'top_p' => 1,
'frequency_penalty' => 0,
'presence_penalty' => 0,
];
I have not yet educated myself on gpt-3.5-turbo so maybe above not needed like past models?
Also, will you be releasing the code you have at http://mm1.ltd/? Like to setup same for some classroom tests.
The new code has been released, and you can try adding these parameters to it. The new code has error prompts, so you can check the error reasons. The specific error information can be viewed from the "errmsg" cookie.
Thank you for reply.
Can you help me understand where to place the above code in new stream.php?
Was clear when using message.php not with stream.php.
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: text/event-stream");
session_start();
$Postscript = $_SESSION['data'];
$ch = curl_init();
$OPENAI_API_KEY = "en-PXQ0A35RLCQaImgLujPST3BlbkFJ2d7Kaa9aJjUqzvYwwkqd";
if ((isset($_SESSION['key'])) && (!empty($_POST['key']))) {
$OPENAI_API_KEY = $_SESSION['key'];
}
$headers = [
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer ' . $OPENAI_API_KEY
];
setcookie("errcode", ""); EventSource cannot get the error message, passed through the cookie
setcookie("errmsg", "");
$callback = function ($ch, $data) {
$complete = json_decode($data);
if (isset($complete->error)) {
setcookie("errcode", $complete->error->code);
setcookie("errmsg", $data);
if (strpos($complete->error->message, "Rate limit reached") === 0) { The code returned by the access frequency overrun error is empty, so special handling is given
setcookie("errcode", "rate_limit_reached");
}
} else {
echo $data;
}
return strlen($data);
};
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/chat/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $Postscript);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback);
//curl_setopt($ch, CURLOPT_PROXY, "http://127.0.0.1:1081");
curl_exec($ch);
curl_close($ch);
OK, I open my eyes after morning coffee:) I think now the postdata is handled in setsession.php?