+
95
-

php如何访问chatgpt api接口流式输出?

php如何访问chatgpt api接口流式输出?


网友回复

+
15
-

增加stream=true

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.openai.com/v1/chat/completions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$messages = [["role" => "system",
    "content" => "你是一个AI助手chatai"]];

$messages[] = ["role" => "user",
    "content" => "你好"];
$_postobj = array("model" => "gpt-3.5-turbo",
    "messages" => $messages,
    "max_tokens" => 100,
    "temperature" => 0.1,
    // "top_p" => 1,
    "n" => 1,
    "stream" => true
);


curl_setopt($ch, CURLO...

点击查看剩余70%

我知道答案,我要回答