ChatGPT 是一个超级对话模型,目前,ChatGPT 处于测试阶段(chat.openai.com),只要有 OpenAI 账户就可以免费使用。可以帮你写代码,可以做数学题,可以做菜谱,可以学英文,可以翻译外语,可以写文章。
一、申请OpenAI(ChatGPT)密钥
1、在 OpenAI 网站上注册一个账号
官网:https://chat.openai.com/chat
2、登录到你的 OpenAI 账号
在主页上找到“API Keys”部分,并点击“Create API Key”按钮。

在弹出的对话框中输入 API 密钥的描述(例如“My API Key”),然后点击“Create”按钮。 你的 API 密钥会出现在“API Keys”部分,你可以复制它并将它保存到你的代码中。
二、PHP代码实现
接口地址:https://api.openai.com/v1/engines/davinci/completions
<?php
$api_key = ‘xxxxx’;
$curl = curl_init();
curl_setopt_array($curl, [
  CURLOPT_URL => 'https://api.openai.com/v1/engines/davinci/completions',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $api_key
  ],
  CURLOPT_POSTFIELDS => json_encode([
    'prompt' => 'Hello, how are you today?',
    'model' => 'text-davinci-002',
    'max_tokens' => 128,
    'temperature' => 0.5
  ])
]);
$response = curl_exec($curl);
curl_close($curl);
?>
                     
                     
                     
                                 
                                 
                         
                         
                         
                         
                         
                         
                         
                         
                
                 
                         
                         
                         
                         
                 关于简忆
关于简忆 简忆诞生的故事
简忆诞生的故事 
            


 粤ICP备16092285号
粤ICP备16092285号
文章评论(0)