{"id":1649,"date":"2022-12-20T12:12:31","date_gmt":"2022-12-20T03:12:31","guid":{"rendered":"https:\/\/tech.at-iroha.jp\/?p=1649"},"modified":"2026-04-06T13:52:26","modified_gmt":"2026-04-06T04:52:26","slug":"openai-apigpt-3-%e3%81%ae%e5%88%a9%e7%94%a8%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/tech.at-iroha.jp\/?p=1649","title":{"rendered":"OpenAI API (GPT-3) \u306e\u5229\u7528\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u5148\u6708\u3001OpenAI\u304b\u3089\u5bfe\u8a71\u578bAI\u3001ChatGPT\uff08https:\/\/chat.openai.com\/chat\uff09\u304c\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u3001\u305d\u306e\u5b8c\u6210\u5ea6\u3068\u6c4e\u7528\u6027\u306e\u9ad8\u3055\u304b\u3089\u5404\u6240\u3067\u8a71\u984c\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u30022020\u5e74\u9803\u304b\u3089GPT-3\u3092\u30d9\u30fc\u30b9\u3068\u3057\u305f\u30b5\u30fc\u30d3\u30b9\u304c\u5ea6\u3005\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u3001\u8a71\u984c\u3068\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u304c\u3001\u3053\u308c\u3089\u306f\u3042\u304f\u307e\u3067\u3082\u7279\u5b9a\u306e\u6a5f\u80fd\u3092\u652f\u63f4\u3059\u308b\u3082\u306e\u306b\u7559\u307e\u3063\u3066\u304a\u308a\u307e\u3057\u305f\u3002\u307e\u305f\u305d\u308c\u4ee5\u524d\u304b\u3089\u5bfe\u8a71\u578bAI\u3082\u5b58\u5728\u3057\u307e\u3057\u305f\u304c\u3001\u305d\u308c\u3089\u306f\u5b9a\u578b\u7684\u306a\u8cea\u554f\u306b\u7b54\u3048\u305f\u308a\u3001\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u62bd\u51fa\u3057\u3066\u691c\u7d22\u7d50\u679c\u3092\u51fa\u529b\u3059\u308b\u306b\u7559\u307e\u3063\u3066\u3044\u307e\u3057\u305f\u3002\u3057\u304b\u3057ChatGPT\u3067\u306f\u3001\u591a\u5c11\u3042\u3044\u307e\u3044\u306a\u8cea\u554f\u3067\u3082\u3001\u6587\u8108\u3084\u3053\u3061\u3089\u306e\u610f\u56f3\u3092\u7406\u89e3\u3057\u3001\u6b63\u76f4\u3001\u6050\u6016\u5fc3\u3092\u611f\u3058\u308b\u307b\u3069\u81ea\u7136\u3067\u7684\u78ba\u306a\u56de\u7b54\u304c\u51fa\u529b\u3055\u308c\u3001\u79c1\u3082\u305d\u306e\u5b8c\u6210\u5ea6\u306e\u9ad8\u3055\u306b\u3068\u3066\u3082\u9a5a\u3044\u3066\u3044\u307e\u3059\u3002\u6700\u8fd1\u306f Google \u3067\u306f\u306a\u304f\u3001ChatGPT \u3067\u8abf\u3079\u7269\u3084\u554f\u984c\u89e3\u6c7a\u3092\u3059\u308b\u3053\u3068\u304c\u5897\u3048\u3066\u304d\u307e\u3057\u305f\u3002\u4ed6\u306b\u3082\u69d8\u3005\u306a\u3053\u3068\u306b\u5fdc\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3082\u306e\u3068\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u73fe\u5728\u3001ChatGPT \u306e API \u306f\u516c\u958b\u3055\u308c\u3066\u304a\u308a\u307e\u305b\u3093\u304c\u3001Open AI \u304b\u3089 GPT-3 \u306eAPI\u304c\u516c\u958b\u3055\u308c\u3066\u304a\u308a\u3001\u7c21\u5358\u306a\u767b\u9332\u3067\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u305f\u305f\u3081\u3001API\u3092\u5229\u7528\u3059\u308b\u307e\u3067\u306e\u624b\u9806\u3092\u7c21\u5358\u306b\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">OpenAI \u306b\u3066API Key \u3092\u767a\u884c<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>OpenAI\u306e\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u53f3\u4e0a\u306e\u300cSign up\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<br><a href=\"https:\/\/beta.openai.com\/signup\">https:\/\/beta.openai.com\/signup<\/a><\/li>\n\n\n\n<li>\u65b0\u898f\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u4f5c\u6210\u3057\u3001\u30ed\u30b0\u30a4\u30f3\u3057\u307e\u3059\u3002<br>Google \u30a2\u30ab\u30a6\u30f3\u30c8\u304c\u3042\u308c\u3070\u7c21\u5358\u306b\u767b\u9332\u53ef\u80fd\u3067\u3059\u3002<\/li>\n\n\n\n<li>ORGANIZATION \u30e1\u30cb\u30e5\u30fc\u304b\u3089\u3001[API Keys] \u3092\u9078\u629e\u3057\u3001\u300cCreate new secret key\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"628\" src=\"https:\/\/tech.at-iroha.jp\/wp-content\/uploads\/2022\/12\/image-4.png\" alt=\"\" class=\"wp-image-1654\" srcset=\"https:\/\/tech.at-iroha.jp\/wp-content\/uploads\/2022\/12\/image-4.png 1024w, https:\/\/tech.at-iroha.jp\/wp-content\/uploads\/2022\/12\/image-4-700x429.png 700w, https:\/\/tech.at-iroha.jp\/wp-content\/uploads\/2022\/12\/image-4-768x471.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>4. \u767a\u884c\u3055\u308c\u305f API Key \u3092\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002<br>\u203b \u3053\u306eAPI Key \u306f\u5f8c\u304b\u3089\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u305f\u3081\u3001\u5fc5\u305a\u3069\u3053\u304b\u306b\u4fdd\u5b58\u3057\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u5b9f\u884c<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u3001HTML\u30d5\u30a9\u30fc\u30e0\u304b\u3089POST\u3055\u308c\u305f\u8cea\u554f\u3092 Open AI API \u306b\u9001\u4fe1\u3057\u3001\u56de\u7b54\u3092\u51fa\u529b\u3059\u308bPHP\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3067\u3059\u3002 $API_KEY \u306bOpen AI \u306e\u30b5\u30a4\u30c8\u3067\u767a\u884c\u3057\u305f API Key \u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/\n\/\/ OpenAI \u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u4f5c\u6210 (<a href=\" https:\/\/beta.openai.com\/signup\"> https:\/\/beta.openai.com\/signup<\/a> )\n\/\/ API Key \u3092\u53d6\u5f97 ( https:\/\/beta.openai.com\/account\/api-keys )\n\/\/\n$API_KEY = 'API Key';\n\n$header = &#91;\n\t'Authorization: Bearer '.$API_KEY,\n\t'Content-type: application\/json',\n];\n\n\/\/$question = 'ChatGPT\u306b\u3064\u3044\u3066\u6559\u3048\u3066\u304f\u3060\u3055\u3044\u3002';\n$question = $_POST&#91;'question'];\n\n$params = json_encode(&#91;\n\t'prompt'\t\t=&gt; $question,\n\t'model'\t\t\t=&gt; 'text-davinci-003',\n\t'temperature'\t=&gt; floatval($_POST&#91;'temperature']),\n\t'max_tokens'\t=&gt; floatval($_POST&#91;'max_tokens']),\n\t'top_p'\t\t\t=&gt; floatval($_POST&#91;'top_p']),\n\t'frequency_penalty'\t=&gt; floatval($_POST&#91;'frequency_penalty']),\n\t'presence_penalty'\t=&gt; floatval($_POST&#91;'presence_penalty'])\n]);\n\n$curl = curl_init('https:\/\/api.openai.com\/v1\/completions');\n\n$options = &#91;\n\tCURLOPT_POST =&gt; true,\n\tCURLOPT_HTTPHEADER =&gt;$header,\n\tCURLOPT_POSTFIELDS =&gt; $params,\n\tCURLOPT_RETURNTRANSFER =&gt; true,\n];\n\ncurl_setopt_array($curl, $options);\n\n$response = curl_exec($curl);\n\n$httpcode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);\n\nif(200 == $httpcode)\n{\n\t$json_array = json_decode($response, true);\n\t$choices = $json_array&#91;'choices'];\n\t\n\tforeach($choices as $c)\n\t{\n\t\techo $c&#91;'text'].'&lt;br&gt;';\n\t}\n}\n?&gt;<\/code><\/pre>\n\n\n\n<p>API \u306b\u9001\u4fe1\u3059\u308b\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5185\u5bb9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>model<\/td><td>\u4f7f\u7528\u3059\u308b\u8a00\u8a9e\u30e2\u30c7\u30eb\u3002<br> GPT-3 \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u300ctext-davinci-003\u300d \u3092\u6307\u5b9a\u3002<\/td><\/tr><tr><td>prompt<\/td><td>\u8cea\u554f\u5185\u5bb9\u3002<\/td><\/tr><tr><td>temperature<\/td><td>\u751f\u6210\u3059\u308b\u30c8\u30fc\u30af\u30f3\u3092\u30b5\u30f3\u30d7\u30ea\u30f3\u30b0\u3059\u308b\u78ba\u7387\u3001\u30e9\u30f3\u30c0\u30e0\u6027\u3002<br>\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\uff1a1.0<\/td><\/tr><tr><td>max_tokens<\/td><td>\u30c8\u30fc\u30af\u30f3\u6570\u306e\u4e0a\u9650\u3002<br>1024<\/td><\/tr><tr><td>top_p<\/td><td>Top-p \u30b5\u30f3\u30d7\u30ea\u30f3\u30b0\u3001\u591a\u69d8\u6027\u3002<br>\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\uff1a1.0<\/td><\/tr><tr><td>frequency_penalty<\/td><td>\u983b\u51fa\u30da\u30ca\u30eb\u30c6\u30a3\u3001\u9ad8\u3044\u307b\u3069\u540c\u3058\u8a71\u984c\u3092\u7e70\u308a\u8fd4\u3055\u306a\u304f\u306a\u308b\u3002<br>\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\uff1a0<\/td><\/tr><tr><td>presence_penalty<\/td><td>\u30d7\u30ec\u30bc\u30f3\u30b9\u30da\u30ca\u30eb\u30c6\u30a3\u3001\u9ad8\u3044\u307b\u3069\u65b0\u3057\u3044\u30c8\u30d4\u30c3\u30af\u304c\u51fa\u73fe\u3057\u3084\u3059\u304f\u306a\u308b\u3002<br>\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\uff1a0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u8a73\u7d30\u306b\u306f\u4ee5\u4e0b\u306eOpenAI\u793e\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p>Open AI API reference &#8211; Completions<br><a href=\"https:\/\/platform.openai.com\/docs\/api-reference\/completions\">https:\/\/platform.openai.com\/docs\/api-reference\/completions<\/a><\/p>\n\n\n\n<p>\u5b9f\u969b\u306b\u30c7\u30e2\u30da\u30fc\u30b8\u3092\u4f5c\u6210\u3044\u305f\u3057\u307e\u3057\u305f\u3002\u4e88\u7b97\u306e\u4e0a\u9650\u306b\u9054\u3057\u305f\u3089\u505c\u6b62\u3057\u307e\u3059\u3002\u5c65\u6b74\u7b49\u306f\u53d6\u3063\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<p>OpenAI API(GPT-3)\u3068\u306e\u5bfe\u8a71<br><a href=\"https:\/\/labs.irohasoft.com\/openai\/\">https:\/\/labs.irohasoft.com\/openai\/<\/a><br><br>API \u306e\u8ab2\u91d1\u72b6\u6cc1\u306b\u3064\u3044\u3066\u306f[Usage]\u306b\u3066\u3001\u5f8c\u304b\u3089\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u306b\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br>\u767b\u9332\u5f8c\u300118\u30c9\u30eb\u5206\u306e\u5229\u7528\u67a0\u304c\u7121\u6599\u3067\u5272\u308a\u5f53\u3066\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"636\" src=\"https:\/\/tech.at-iroha.jp\/wp-content\/uploads\/2022\/12\/image-3-1024x636.png\" alt=\"\" class=\"wp-image-1653\" srcset=\"https:\/\/tech.at-iroha.jp\/wp-content\/uploads\/2022\/12\/image-3-1024x636.png 1024w, https:\/\/tech.at-iroha.jp\/wp-content\/uploads\/2022\/12\/image-3-700x435.png 700w, https:\/\/tech.at-iroha.jp\/wp-content\/uploads\/2022\/12\/image-3-768x477.png 768w, https:\/\/tech.at-iroha.jp\/wp-content\/uploads\/2022\/12\/image-3.png 1191w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u6708\u3001OpenAI\u304b\u3089\u5bfe\u8a71\u578bAI\u3001ChatGPT\uff08https:\/\/chat.openai.com\/chat\uff09\u304c\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u3001\u305d\u306e\u5b8c\u6210\u5ea6\u3068\u6c4e\u7528\u6027\u306e\u9ad8\u3055\u304b\u3089\u5404\u6240\u3067\u8a71\u984c\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u30022020\u5e74\u9803\u304b\u3089GPT-3\u3092\u30d9\u30fc\u30b9\u3068\u3057\u305f\u30b5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1654,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1649","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nlp"],"_links":{"self":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts\/1649","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1649"}],"version-history":[{"count":17,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts\/1649\/revisions"}],"predecessor-version":[{"id":1703,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts\/1649\/revisions\/1703"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/media\/1654"}],"wp:attachment":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}