You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
762 B
PHP

<?php
$context = json_decode($_POST['context'] ?: "[]") ?: [];
$postData = [
"model" => "gpt-3.5-turbo",
"temperature" => 0,
"stream" => true,
"messages" => [],
];
if (!empty($context)) {
$context = array_slice($context, -5);
foreach ($context as $message) {
$postData['messages'][] = ['role' => 'user', 'content' => str_replace("\n", "\\n", $message[0])];
$postData['messages'][] = ['role' => 'assistant', 'content' => str_replace("\n", "\\n", $message[1])];
}
}
$postData['messages'][] = ['role' => 'user', 'content' => $_POST['message']];
$postData = json_encode($postData);
session_start();
$_SESSION['data'] = $postData;
if (isset($POST['key'])) {
$_SESSION['key'] = $_POST['key'];
}
echo '{"success":true}';