ChatGPT PHP
1.聊天模型图片生成
//API 替换自己注册的
$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_URL => "https://api.openai.com/v1/chat/completions",CURLOPT_RETURNTRANSFER => true,CURLOPT_ENCODING => "",CURLOPT_MAXREDIRS => 10,CURLOPT_TIMEOUT => 0,CURLOPT_FOLLOWLOCATION => true,CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,CURLOPT_CUSTOMREQUEST => "POST",CURLOPT_POSTFIELDS => json_encode(array("model" => "gpt-3.5-turbo",'max_tokens' => 2000,"messages" => [array("role" => "user", "content" => $prompt)],)),CURLOPT_HTTPHEADER => array("Content-Type: application/json","Authorization: Bearer API",),
));
$response = curl_exec($curl);
curl_close($curl);
2.图片生成
//API 替换自己注册的
$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_URL => "https://api.openai.com/v1/images/generations",CURLOPT_RETURNTRANSFER => true,CURLOPT_ENCODING => "",CURLOPT_MAXREDIRS => 10,CURLOPT_TIMEOUT => 0,CURLOPT_FOLLOWLOCATION => true,CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,CURLOPT_CUSTOMREQUEST => "POST",CURLOPT_POSTFIELDS => json_encode(array("prompt" => $prompt,"n" => 1,"size" => "1024x1024",'response_format' => "b64_json",)),CURLOPT_HTTPHEADER => array("Content-Type: application/json","Authorization: Bearer API",),
));
$response = curl_exec($curl);
curl_close($curl);
个人技术博客:Aquarius Boy Blog 不定时更新 欢迎大家申请入驻!
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
