2024年11月21日

HYEOS

随事而为

wordpress chat-gpt api示例

 "https://api.openai.com/v1/engines/text-davinci-002/jobs",
  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 =>"{\"prompt\":\"".$prompt."\",\"max_tokens\":1024}",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/json",
    "Authorization: Bearer ".$api_key
  ),
));

$response = curl_exec($curl);

curl_close($curl);

$response_json = json_decode($response, true);

$generated_text = $response_json['choices'][0]['text'];

// Use the generated text in your WordPress plugin as needed.

?>

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注