php curl获取流式数据
未知
2024-04-16 13:55:24
0次
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token={$this->getAccessToken()}",
CURLOPT_TIMEOUT => 130,
CURLOPT_RETURNTRANSFER => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"messages":[{"role":"user","content":"'.$content.'"}],"stream": true}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
CURLOPT_WRITEFUNCTION=>function($ch, $chunk){
//不能返回$chunk
return strlen($chunk);
}
));
$response = curl_exec($curl);
//$response返回true/false
curl_close($curl);
相关内容