• 16-12-2023, 11:59:25
    #19
    Üyeliği durduruldu
    es üstad

    jeptun adlı üyeden alıntı: mesajı görüntüle
    gece boş bir aralıkta can sıkıntısından hazırladım ben beyler işine yarayan olursa kullansın

    <?php
    
    /**
     * R10 AI : Finding  the category of content with AI
     * Author : Jeptun | Murat Y.
     */
    
    
    class R10GPT {
        
        private $api_key     = null;
        private $api_url        = "https://api.openai.com/v1/completions";
        private $api_model      = "text-davinci-003";
        private $prompt         = null;
        private $max_token      = 2000;
        private $temperature = 0.7;
    
        /**
         *
         */
        public function __construct() {
    
    
    
        }
    
    
        /**
         * Set API key
         */
        public function set_api($key) {
    
            if($key == null) {
                die("error : set_api value cannot be empty");
            }
    
            $this->api_key = $key;
            return $this;
    
        }
    
        /**
         * Set API model
         */
        public function set_token($token) {
    
            $this->max_token = $token;
            return $this;
    
        }
    
        /**
         * Set API prompt
         */
        public function set_prompt($prompt) {
    
            if($prompt == null) {
                die("error : set_prompt value cannot be empty");
            }
    
            $this->prompt = $prompt;
            return $this;
    
        }
    
        /**
         * Get API prompt
         */
        public function get_prompt() {
    
            $categories             = '"finans, adsense, adwords, yardım, adsense hikayem, günlük yaşam, gündem, tarih , ülkeler"';
            $title                     = $this->prompt;
    
            $generate_prompt         = $categories . ' kategorilerinden hangisi '. $title .' başlığına uygun ise yalnızca o kategoriyi json olarak ekrana yazdır. json çıktısı ise {"category:category"} formatında olsun.  çıktı senin fikirlerini ve açıklamalarını içermesin.';
    
            $prompt["model"]         = $this->api_model;
            $prompt["prompt"]         = $generate_prompt;
            $prompt["temperature"]     = $this->temperature;
            $prompt["max_tokens"]     = $this->max_token;
    
            return $prompt;
        }
    
        /**
         * Get API headers
         */
        public function get_headers() {
    
            $headers = ['Authorization: Bearer ' . $this->api_key , 'Content-Type: application/json'];
            
            return $headers;
        }
    
        /**
         * cURL connection
         */
        public function run() {
    
            $ch  = curl_init($this->api_url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->get_prompt()));
            curl_setopt($ch, CURLOPT_HTTPHEADER, $this->get_headers());
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($ch);
            curl_close($ch);
    
            if($response){
    
                $responseData = json_decode($response, true);
                $output       = $responseData['choices'][0]['text'];
                return $output;
    
            }else{
    
                return "API Request failed!";
                        
            }
    
    
        }
    
    }
    
    
    /**
     * Finding  a category for the title sent via POST method
     */
    
    if($_SERVER['REQUEST_METHOD'] === "POST"){
    
        if(isset($_POST['title'])){
    
            $input = $_POST['title'];
    
            if(!empty($input)){
    
                $ai = new R10GPT;
    
                $data = $ai->set_api("BURAYA API KEY GELECEK")
                    ->set_prompt($input)
                    ->run();
    
                echo $data;
                die();
    
            }else{
    
                echo json_encode(["category" => "error"]);
                die();
    
            }
        }
    }
    
    
    
    ?>
    
    
    
    
    <!doctype html>
    <html lang="en">
      <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
        <script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>
        <title>R10 AI</title>
      </head>
      <body>
          <div class="container py-3">
            <div class="row">
              <div class="col-md-12">
                <h2 class="text-center mb-3 d-none" id="category"></h2>
                <div class="row justify-content-center">
                  <div class="col-md-6">
                    <span class="anchor" id="formLogin"></span>
                    <div class="card card-outline-secondary">
                      <div class="card-body">
                          <div class="form-group">
                            <label for="uname1">başlık</label>
                            <input class="form-control" id="title" name="title" required="" type="text">
                          </div>
                            <button onclick="send_btn()" class="btn btn-success btn-lg float-right" type="button">kategori bul</button>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
    
    
    
    
        <script type="text/javascript">
    
            function send_btn(){
    
                var title = $("#title").val();
    
                $.ajax({
                  type: "POST",
                  url: window.location.href,
                    data: "title=" + title,
                  dataType: 'JSON',
                  beforeSend: function () {
    
                     $("#send").removeClass('d-none');
    
                  },
                  success: function (data) {
    
                     $("#send").removeClass('d-none');
                     $("#category").removeClass('d-none');
                     $("#category").text(data.category);
    
                  },
                  error: function (error) {
    
                     $("#sending").removeClass('d-none');
    
                  }
               })
    
    
            }
        </script>
    
    
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
      </body>
    </html>
  • 16-12-2023, 11:59:35
    #20
    Üyeliği durduruldu
    yengec35 adlı üyeden alıntı: mesajı görüntüle
    Elinize emeğinize sağlık yöneticiler görüp beğenirlerse eklenirse harika bir özellik olur