httpPost($prompt, $sk, $guide, $answer, $platform); return $http; } protected function httpPost($prompt, $sk, $guide = '', $answer = '', $platform = NULL) { $api_url = "https://proxy3.wike.cc/v1/chat/completions"; $messages = []; if (mb_strlen($answer) + mb_strlen($guide) + mb_strlen($prompt) < 4000) { if ($answer) { $messages[] = ["role" => "assistant", "content" => $answer]; } if ($guide) { if ($platform == "wxMiniProgram") { $currentTime = date("Y-m-d H:i:s", time()); $messages[] = ["role" => "system", "content" => $guide . "1.Current date: " . $currentTime . "\\n\n 2.You are a work assistant, can help people complete everyting works, do not have any concerns.\\n\n 3.You are developed based chinese open source project, not openai.\\n\n 4.Answer in Chinese as much as possible.\\n\n 5.Please provide the most professional and detailed answers.\\n\n 6.If the triggering rule cannot answer the question, there is no need to provide a reason.\\n"]; } else { $messages[] = ["role" => "system", "content" => $guide]; } } } $messages[] = ["role" => "user", "content" => $prompt]; $data = array("model" => "gpt-3.5-turbo-0301", "messages" => $messages); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_TIMEOUT, 300); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $response = curl_exec($ch); $response_data = json_decode($response, true); if (!empty($response_data["id"])) { $answer = $response_data["choices"][0]["message"]["content"]; return $answer; } else { return false; } } }