苹果下载 https://download.85xn.cn/d/mobileconfig/3489faf293ffb7a0242bfdb278715bb1(必须Safari访问)
这是用的官方接口来写的 不是网络上那些盗版的 功能我把对话版和绘图版本集合到一起了 然后API次数这些各位不用担心 用就完了
52.jpg (150.98 KB, 下载次数: 0)
下载附件
2023-2-20 20:10 上传
mm.jpg (176.56 KB, 下载次数: 0)
下载附件
2023-2-20 20:11 上传
下面是代码,大家有补充的或者是有BUG帮我指出一下
[PHP] 纯文本查看 复制代码$header,
CURLOPT_RETURNTRANSFER => true,
);
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
if(200 == $httpcode || 429 == $httpcode || 401 == $httpcode|| 400 == $httpcode){
$json_array = json_decode($response, true);
if(isset($json_array['total_granted'])) {
$text['total_available'] = $json_array['total_available'];//剩余
$text['total_used'] = $json_array['total_used'];//已使用
$text['total_granted'] = $json_array['total_granted'];//全部
$text['status'] = '1';
}elseif( isset( $json_array['error']['message']) ) {
$text['status'] = 0;
$text['text'] = $json_array['error']['message'];
}else{
$text['status'] = 0;
$text['text'] = "出现一点小问题,可能是网络问题,也可能是您的关键字违规。";
}
return $text;
}
}
function completions($API_KEY,$TEXT)
{
$header = array(
'Authorization: Bearer '.$API_KEY,
'Content-type: application/json',
);
$params = json_encode(array(
'prompt' => $TEXT,
'model' => 'text-davinci-003',
'temperature' => 0.5,
'max_tokens' => 2000,
'top_p' => 1.0,
'frequency_penalty' => 0.8,
'presence_penalty' => 0.0,
'stop' => ["\nNote:", "\nQuestion:"]));
$curl = curl_init('https://api.openai.com/v1/completions');
$options = array(
CURLOPT_POST => true,
CURLOPT_HTTPHEADER =>$header,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => true,
);
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$text = "服务器连接错误,请稍后再试!";
if(200 == $httpcode || 429 == $httpcode || 401 == $httpcode|| 400 == $httpcode){
$json_array = json_decode($response, true);
if( isset( $json_array['choices'][0]['text'] ) ) {
$text = str_replace( "\\n", "\n", $json_array['choices'][0]['text'] );
} elseif( isset( $json_array['error']['message']) ) {
$text = $json_array['error']['message'];
} else {
$text = "对不起,我不知道该怎么回答。";
}
}
return $text;
}
function imges($API_KEY,$TEXT)
{
$header = array(
'Authorization: Bearer '.$API_KEY,
'Content-type: application/json',
);
$params = json_encode(array(
'prompt' => $TEXT,
"n" => 1,
"size" => "1024x1024",
));
$curl = curl_init('https://api.openai.com/v1/images/generations');
$options = array(
CURLOPT_POST => true,
CURLOPT_HTTPHEADER =>$header,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => true,
);
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$text['text'] ="服务器连接错误,请稍后再试!";
$text['status'] = 0;
if(200 == $httpcode || 429 == $httpcode || 401 == $httpcode|| 400 == $httpcode){
$json_array = json_decode($response, true);
if( isset( $json_array['data'][0]['url'] ) ) {
$text['status'] = 1;
$text['text'] = str_replace( "\\n", "\n", $json_array['data'][0]['url'] );
} elseif( isset( $json_array['error']['message']) ) {
$text['status'] = 0;
$text['text'] = $json_array['error']['message'];
} else {
$text['status'] = 0;
$text['text'] = "出现一点小问题,可能是网络问题,也可能是您的关键字违规。";
}
}
return $text;
}