带PHP

问题描述 投票:0回答:1
$apiKey='xxxxxxxxxxxxxxx'; $url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent? key=$apiKey"; $query['text']='Why has Google search gotten so bad?'; $message['role']='user'; $message['parts']=array($query); $data['contents']=array($message); $payload=json_encode($data); $headers=['Content-Type:application/json','X-GEMINI-APIKEY:'.$apiKey]; $ch=curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); $response=curl_exec($ch); curl_close($ch); $result=json_decode($response,true); echo $result['candidates'][0]['content']['parts'][0]['text'];

php curl artificial-intelligence google-gemini
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.