{"id":13026,"date":"2023-05-18T10:00:00","date_gmt":"2023-05-18T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=13026"},"modified":"2023-05-17T19:06:00","modified_gmt":"2023-05-17T10:06:00","slug":"openai-gpt-api2","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/13026","title":{"rendered":"OpenAI GPT API(2)"},"content":{"rendered":"\n<p>\u4eca\u56de\u306fOpenAI\u306eCompletionAPI\u3092\u4f7f\u7528\u3057\u3066\u30b7\u30f3\u30d7\u30eb\u306a\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br>\u4ee5\u4e0b\u306e\u5b9f\u88c5\u3092\u8a66\u3059\u306b\u306fOpenAI\u306eAPI\u30ad\u30fc\u304c\u5fc5\u9808\u306b\u306a\u308a\u307e\u3059\u3002API\u30ad\u30fc\u306e\u53d6\u5f97\u65b9\u6cd5\u306f<a href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12981\" target=\"_blank\" rel=\"noreferrer noopener\">\u524d\u56de\u306e\u8a18\u4e8b<\/a>\u3067\u8aac\u660e\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h4>OpenAI Python\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u4f7f\u7528\u65b9\u6cd5<\/h4>\n\n\n\n<p><a href=\"https:\/\/platform.openai.com\/docs\/api-reference?lang=python\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/platform.openai.com\/docs\/api-reference?lang=python<\/a><\/p>\n\n\n\n<p>\u4e0a\u8a18\u306eAPI\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u306b\u8a18\u8f09\u306e\u65b9\u6cd5\u3067OpenAI Python\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<br>Notebook\u3092\u958b\u3044\u3066\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>pip install openai<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"815\" height=\"265\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/05\/1-1.png\" alt=\"\" class=\"wp-image-13027\" \/><\/figure>\n\n\n\n<p><br>\u79c1\u306e\u74b0\u5883\u3067\u306f\u3059\u3067\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u305f\u306e\u3067\u300cRequirement already satisfied\u300d\u3068\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u304c\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u4e0a\u8a18\u30b3\u30de\u30f3\u30c9\u3067OpenAI Python\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>OpenAI Python\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001\u6b21\u306fimport\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>import openai<\/p>\n\n\n\n<p>import\u304c\u5b8c\u4e86\u3057\u305f\u3089OpenAI\u306eCompletionAPI\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u307e\u3059\u3002<br>CompletionAPI\u4ee5\u5916\u306bChatAPI\u3084\u753b\u50cf\u751f\u6210\u3001\u97f3\u58f0\u8a8d\u8b58\u306eAPI\u306a\u3069\u3082\u3042\u308a\u307e\u3059\u304c\u3001<br>\u4eca\u56de\u306fAPI\u306e\u52d5\u4f5c\u78ba\u8a8d\u306e\u305f\u3081\u306b\u30b7\u30f3\u30d7\u30eb\u306a\u30c6\u30ad\u30b9\u30c8\u751f\u6210\u306eCompletionAPI\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br>\u4ee5\u4e0b\u304c\u8a18\u8ff0\u4f8b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openai.Completion.create(\n    model=\"text-davinci-003\",\n    prompt=\"tagline for an ice cream shop is\"  \n)\n<\/code><\/pre>\n\n\n\n<p><br>\u5f15\u6570\u304c\u6700\u4f4e2\u3064\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3072\u3068\u3064\u3081\u306e\u5f15\u6570\uff1a\u300cmodel\u300d\u306b\u3064\u3044\u3066<br>OpenAI API\u306b\u306f\u3001\u69d8\u3005\u306amodel\u304c\u7528\u610f\u3055\u308c\u3066\u304a\u308a\u3001\u4f7f\u7528\u7528\u9014\u306b\u5fdc\u3058\u3066\u4f7f\u3044\u5206\u3051\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<br>\u305d\u308c\u305e\u308c\u306emodel\u306e\u9055\u3044\u3084\u6599\u91d1\u4f53\u7cfb\u306a\u3069\u306f\u6b21\u56de\u8aac\u660e\u3057\u307e\u3059\u3002<br>\u4eca\u56de\u306f&#8221;text-davinci-003&#8243;\u3068\u3044\u3046model\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3075\u305f\u3064\u3081\u306e\u5f15\u6570\uff1a\u300cprompt\u300d\u306b\u3064\u3044\u3066<br>CompletionAPI\u306f\u4e0d\u5b8c\u5168\u306a\u6587\u7ae0\u304b\u3089\u6b21\u306b\u304f\u308b\u6587\u7ae0\u3092\u63a8\u6e2c\u3057\u3066\u6587\u7ae0\u3092\u7d9a\u3051\u307e\u3059\u3002<br>\u8a66\u3057\u306b\u300ctagline for an ice cream shop is\u300d(\u30a2\u30a4\u30b9\u30af\u30ea\u30fc\u30e0\u5e97\u306e\u30ad\u30e3\u30c3\u30c1\u30d5\u30ec\u30fc\u30ba\u306f)<br>\u3068\u3044\u3046\u6587\u7ae0\u3092\u5165\u529b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3067\u306f\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"890\" height=\"144\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/05\/2-1.png\" alt=\"\" class=\"wp-image-13033\" \/><\/figure>\n\n\n\n<p>\u30a8\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<br>CompletionAPI\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u306b\u306fAPI\u30ad\u30fc\u306b\u3088\u308b\u8a8d\u8a3c\u304c\u5fc5\u8981\u3067\u3059\u3002<br>API\u30ad\u30fc\u306b\u3088\u308b\u8a8d\u8a3c\u3092\u304a\u3053\u306a\u3046\u305f\u3081\u306b\u306f\u3001\u4e0a\u8a18\u30a8\u30e9\u30fc\u5185\u5bb9\u306e\u9752\u67a0\u7b87\u6240\u306e\u5185\u5bb9\u3067<br>API\u30ad\u30fc\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3092\u304a\u3053\u306a\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"532\" height=\"93\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/05\/4.png\" alt=\"\" class=\"wp-image-13034\" \/><\/figure>\n\n\n\n<p><br>\u4eca\u56de\u306f\u8aac\u660e\u3092\u7c21\u5358\u306b\u3059\u308b\u305f\u3081API\u30ad\u30fc\u3092\u76f4\u66f8\u304d\u3057\u3066\u3044\u307e\u3059\u304c\u3001<br>\u5b9f\u969b\u306b\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u3001.env\u30d5\u30a1\u30a4\u30eb\u306a\u3069\u306e\u4e0d\u53ef\u8996\u30d5\u30a1\u30a4\u30eb\u306bAPI\u30ad\u30fc\u3092\u8a18\u8f09\u3057\u3066<br>\u30b3\u30fc\u30c9\u5185\u306b\u30ad\u30fc\u3092\u542b\u307e\u305b\u306a\u3044\u3001\u3055\u3089\u306b.env\u30d5\u30a1\u30a4\u30eb\u3092gitignore\u306b\u8ffd\u52a0\u3059\u308b\u306a\u3069<br>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u9762\u3067\u306e\u914d\u616e\u3082\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p>API\u30ad\u30fc\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u304c\u3067\u304d\u307e\u3057\u305f\u306e\u3067\u3001\u518d\u5ea6CompletionAPI\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"592\" height=\"293\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/05\/3.png\" alt=\"\" class=\"wp-image-13036\" \/><\/figure>\n\n\n\n<p><br>\u3053\u306e\u3088\u3046\u306a\u7d50\u679c\u304c\u51fa\u529b\u3055\u308c\u307e\u3057\u305f\u3002<br>\u7d50\u679c\u306e\u8d64\u67a0\u90e8\u5206 choices &gt; text \u304cAI\u306b\u3088\u308b\u751f\u6210\u30c6\u30ad\u30b9\u30c8\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u300ctagline for an ice cream shop is\u300d(\u30a2\u30a4\u30b9\u30af\u30ea\u30fc\u30e0\u5e97\u306e\u30ad\u30e3\u30c3\u30c1\u30d5\u30ec\u30fc\u30ba\u306f)<br>\u3068\u3044\u3046\u6587\u7ae0\u306b\u7d9a\u3051\u3066\u3001OpenAI\u306f<br>\u300cBringing coolness to the city\u300d(\u30af\u30fc\u30eb\u30cd\u30b9\u3092\u8857\u306b\u6301\u3061\u8fbc\u3080)<br>\u3068\u3044\u3046\u6587\u7ae0\u3092\u8fd4\u3057\u3066\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>prompt\u90e8\u5206\u3092\u8abf\u6574\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001response\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u898f\u5b9a\u3057\u305f\u308a<br>\u56de\u7b54\u5185\u5bb9\u3092\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u3092\u30d7\u30ed\u30f3\u30d7\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u30ea\u30f3\u30b0<br>(prompt engineering)\u3068\u547c\u3073\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306a\u624b\u6cd5\u3084\u30a2\u30d7\u30ed\u30fc\u30c1\u306e\u65b9\u6cd5\u306a\u3069\u3082<br>\u4eca\u5f8c\u7d39\u4ecb\u3057\u3066\u3044\u3051\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u540c\u3058\u8cea\u554f\u3092\u65e5\u672c\u8a9e\u3067\u304a\u3053\u306a\u3063\u305f\u5834\u5408\u306f\u3069\u3046\u306a\u308b\u306e\u304b\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"622\" height=\"225\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/05\/5.png\" alt=\"\" class=\"wp-image-13037\" \/><\/figure>\n\n\n\n<p>\u65e5\u672c\u8a9e\u3067\u8cea\u554f\u3057\u305f\u5834\u5408\u3001\u65e5\u672c\u8a9e\u3067\u56de\u7b54\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u6b21\u56de\u306fmodel\u306b\u306f\u3069\u3093\u306a\u7a2e\u985e\u304c\u3042\u308b\u304b\u3001API\u4f7f\u7528\u306e\u969b\u306e\u4fa1\u683c\u306e\u7b97\u51fa\u65b9\u6cd5\u306f\u3001<br>GPT\u3092\u3046\u307e\u304f\u4f7f\u3044\u3053\u306a\u3059\u306b\u306fprompt\u3092\u3069\u306e\u3088\u3046\u306b\u8abf\u6574\u3059\u308c\u3070\u3088\u3044\u304b\u3001CompletionAPI\u4ee5\u5916\u306b<br>\u3069\u306e\u3088\u3046\u306aAPI\u304c\u3042\u308b\u306e\u304b\u306a\u3069\u306e\u8aac\u660e\u3092\u304a\u3053\u306a\u3044\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6728\u66dc\u65e5\u62c5\u5f53\uff1anishida<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/13026\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/13026\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"OpenAI GPT API(2)\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/13026\" data-text=\"OpenAI GPT API(2)\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/13026\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/13026\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306fOpenAI\u306eCompletionAPI\u3092\u4f7f\u7528\u3057\u3066\u30b7\u30f3\u30d7\u30eb\u306a\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u5b9f\u88c5\u3092\u8a66\u3059\u306b\u306fOpenAI\u306eAPI\u30ad\u30fc\u304c\u5fc5\u9808\u306b\u306a\u308a\u307e\u3059\u3002API\u30ad\u30fc\u306e\u53d6\u5f97\u65b9\u6cd5\u306f\u524d\u56de\u306e\u8a18\u4e8b\u3067\u8aac\u660e\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u5fc5 [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[96],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/13026"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=13026"}],"version-history":[{"count":8,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/13026\/revisions"}],"predecessor-version":[{"id":13041,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/13026\/revisions\/13041"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=13026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=13026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=13026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}