• 18-05-2023, 14:08:23
    #1
    Kod yazamadığım için bu konuyu açtım, yardımcı olacak arkadaşlar var mı?
    En kolay yolla bu apiyi nasıl kullanabilirim.
  • 18-05-2023, 14:11:42
    #2
    takip
  • 18-05-2023, 14:12:15
    #3
    WordPress sitenizin kök dizininde, wp-content/themes/ klasöründe mevcut temanıza gidin. Tema dizininde bir php dosyası oluştur. botum-api.php gibi. Sonrasında botum-api.php dosyasının içeriğine şu şekilde yazın.
    <?php
    function call_gpt_api($prompt) {
      $api_key = 'API_ANAHTARINIZ';
    
      $headers = array(
        'Content-Type: application/json',
        'Authorization: Bearer ' . $api_key
      );
    
      $data = array(
        'prompt' => $prompt,
        'max_tokens' => 100
      );
    
      $ch = curl_init('https://api.openai.com/v1/engines/davinci-codex/completions');
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
      $response = curl_exec($ch);
      curl_close($ch);
    
      $result = json_decode($response, true);
    
      if (isset($result['choices'][0]['text'])) {
        return $result['choices'][0]['text'];
      } else {
        return 'GPT-3.5 Turbo API yanıtı alınamadı.';
      }
    }
    ?>
    İstediğin bir sayfada veya şablonda GPT-3.5 Turbo API'yi kullanmak için aşağıdaki gibi bir kod parçası ekle.

    <?php
    $prompt = 'API ile gönderilecek metin'; // API'ye göndermek istediğiniz metni buraya ekleyin
    $response = call_gpt_api($prompt);
    echo $response;
    ?>