<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ## 對話聊天API核心代碼如下所示 ##### 看起來很簡單,沒什么業務邏輯,就兩個參數 >[info] > $Questionmessage :你給機器人發的消息,僅限文字 $context:你跟機器人對話的內容上下文,每次都會拼接,這樣機器人會根據你最近的五條對話來回答你接下來的問題,讓機器人看起來顯得沒那么笨笨的感覺。但是有一個前提,<span style="color:red">這個開啟會導致費用增加 </span>返回的結果,需要轉string格式。在前面加一個 `(string)` 即可。 ``` /** * @return void * @throws \Exception * 消息 */ public function ChatGPT($Questionmessage, $context = "[]") { $open_ai = new OpenAi(config("site.key")); // 設置默認的請求文本prompt $prompt = "這是前置內容,每次提交都伴隨此,可以改為空\n\n"; $version = "text-davinci-003"; if (empty($context)) { // 如果沒有內容,下面是默認內容 $prompt .= " Question:\n'我問你個問題,你告訴我答案OK嗎? \n\nAnswer:\n好 \n\n Question:\n'請你輸入你的問題 \n\nAnswer:\n 輸入問題后可以獲取答案 "; $please_use_above = ""; } else { // 將上次的問題和答案作為問題進行提交 $prompt .= ""; $context = array_slice($context, -5); foreach ($context as $message) { $prompt .= "Question:\n" . $message[0] . "\n\nAnswer:\n" . $message[1] . "\n\n"; } $please_use_above = ". Please use the questions and answers above as context for the answer."; } // add new question to prompt $prompt = $prompt . "Question:\n" . $Questionmessage . $please_use_above . "\n\nAnswer:\n\n"; // add new question to prompt $prompt = $prompt . "Question:\n" . $Questionmessage . $please_use_above . "\n\nAnswer:\n\n"; // create a new completion $complete = json_decode($open_ai->completion([ 'model' => $version, 'prompt' => $prompt, 'temperature' => 0.9, 'max_tokens' => 2000, //最大字符數,建議別改大了 'top_p' => 1, 'frequency_penalty' => 0, 'presence_penalty' => 0, 'stop' => [ "\nNote:", "\nQuestion:" ] ])); // get message text if (isset($complete->choices[0]->text)) { $text = str_replace("\\n", "\n", $complete->choices[0]->text); } elseif (isset($complete->error->message)) { $text = $complete->error->message; } else { $text = "Sorry, but I don't know how to answer that."; } return (string)$text; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看