{"id":1699,"date":"2023-03-05T14:46:49","date_gmt":"2023-03-05T14:46:49","guid":{"rendered":"https:\/\/oimi.me\/?p=1699"},"modified":"2023-03-05T14:46:49","modified_gmt":"2023-03-05T14:46:49","slug":"chatgpt%e6%a8%a1%e5%9e%8bgpt3-5%e5%ae%98%e6%96%b9api%e5%bc%80%e6%94%be%ef%bc%8c%e4%bc%98%e5%8c%96%e5%8d%87%e7%ba%a7%e5%bc%80%e6%ba%90%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/myya.net\/index.php\/2023\/03\/05\/chatgpt%e6%a8%a1%e5%9e%8bgpt3-5%e5%ae%98%e6%96%b9api%e5%bc%80%e6%94%be%ef%bc%8c%e4%bc%98%e5%8c%96%e5%8d%87%e7%ba%a7%e5%bc%80%e6%ba%90%e4%bb%a3%e7%a0%81\/","title":{"rendered":"ChatGPT\u6a21\u578bGPT3.5\u5b98\u65b9API\u5f00\u653e\uff0c\u4f18\u5316\u5347\u7ea7\u5f00\u6e90\u4ee3\u7801"},"content":{"rendered":"<p>OpenAI \u5728\u7f8e\u56fd\u65f6\u95f43\u67081\u65e5\u6b63\u5f0f\u5f00\u653e\u4e86ChatGPT\u6a21\u578bGPT3.5\u7684API\u3002\u4e00\u4e0b\u5b50\u5927\u5bb6\u6709\u5fd9\u6d3b\u8d77\u6765\u4e86\uff01<\/p>\n<p>\u535a\u4e3b\u5927\u6982\u7ffb\u9605\u4e86\u4e00\u4e0b\u76f8\u5173\u5185\u5bb9\uff0c\u603b\u7ed3\u4e86\u4e00\u4e9b\u70b9\u5206\u4eab\u4e00\u4e0b\u7ed9\u5927\u5bb6\u3002<\/p>\n<p>\u4e3b\u8981\u8fd8\u662f\u4ecb\u7ecd\u4e00\u4e0b\u65b0\u7684API\u4f7f\u7528\uff0c\u4ee5\u53ca\u535a\u4e3b\u5f00\u6e90\u7684NodeBB ChatGPT\u7684\u4ee3\u7801\u5347\u7ea7\u8fc7\u7a0b\u3002<!--more--><\/p>\n<div class=\"c-alert\">\n<p>\u8ba1\u8d39\u60c5\u51b5<\/p>\n<\/div>\n<p>\u76ee\u524d gpt-3.5-turbo \u4ef7\u683c\u76f8\u5bf9\u4e8e gpt-3\u8981\u4f18\u60e0\u5f88\u591a\uff01<\/p>\n<p>Chat\uff08gpt-3.5\uff09\u4ef7\u683c\uff1a$0.002 \/ 1K tokens<\/p>\n<p>Davinci\uff08gpt-3\uff09 \u4ef7\u683c\uff1a$0.02 \/ 1K tokens<\/p>\n<p>\u6240\u4ee5 gpt-3.5-turbo \u6a21\u578b\u4ef7\u683c\u66f4\u5b9e\u60e0\u4e00\u4e9b\uff01\u4f46\u662f\u5982\u679c\u643a\u5e26\u4e0a\u4e0b\u6587\u63d0\u95ee\uff0c\u8fd8\u662f\u6bd4\u8f83\u8d39tokens\u7684\uff01<\/p>\n<p><strong>1K tokens \u5927\u6982\u662f 750\u4e2a\u5355\u8bcd\uff0c\u65b0\u6ce8\u518c\u7528\u6237\u900118\u7f8e\u5143\u4f53\u9a8c\u4ef7\uff0c\u5927\u6982\u80fd\u4f7f\u7528 900\u4e07\u4e2a\u5355\u8bcd\uff01<\/strong><\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"catalog-h2-1\">\u5b9e\u73b0\u539f\u7406<\/h2>\n<p>\u5176\u5b9e\u5728GPT-3\u6a21\u578b\u5df2\u7ecf\u5f88\u5f3a\u5927\u4e86\uff01\u4f46\u662fChatGPT\u62e5\u6709\u4e0a\u4e0b\u6587\u8bed\u5883\u5173\u8054\uff0c\u5b98\u65b9\u6700\u5f00\u59cb\u672a\u63d0\u4f9bGPT-3.5\u7684\u65f6\u5019\u3002<\/p>\n<p>\u535a\u4e3b\u5728JIKE\u793e\u533a\u7684ChatGPT\u4ee3\u7801\u4e2d\uff0c\u5229\u7528<strong>\u5f15\u7528\u5386\u53f2\u56de\u590d<\/strong>\u7684\u65b9\u5f0f\uff0c\u4e5f\u80fd\u5b9e\u73b0\u4e0a\u4e0b\u6587\u8bed\u5883\u3002\u4f53\u9a8c\u8fd8\u4e0d\u9519\uff01<\/p>\n<p>\u7f3a\u70b9\u5c31\u662f\u6709\u70b9\u8d39\u94b1\uff01\u56e0\u4e3a\u6bcf\u6b21\u5411OpenAI\u63d0\u95ee\u7684\u65f6\u5019\u9700\u8981\u643a\u5e26\u5386\u53f2\u5185\u5bb9\uff0c\u4f1a\u5927\u91cf\u6d88\u8017tokens~<\/p>\n<p>\u73b0\u5728\u5b98\u65b9\u63d0\u4f9b\u4e86\u66f4\u65b9\u4fbf\u7684\u5f62\u5f0f\uff01<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"catalog-h2-2\">\u63a5\u53e3\u4ecb\u7ecd<\/h2>\n<p>\u76ee\u524dChatGPT \u5f00\u653e\u4e862\u4e2a\u6a21\u578b\uff1agpt-3.5-turbo\u00a0 \u548c gpt-3.5-turbo-0301<\/p>\n<p><strong>\u8fd9\u4fe9\u4e2a\u6a21\u578b\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><\/p>\n<p>gpt-3.5-turbo-0301\u6a21\u578b \u662f gpt-3.5-turbo\u6a21\u578b\u7684\u5feb\u7167\uff01gpt-3.5-turbo-0301\u4e0d\u4f1a\u81ea\u6211\u66f4\u65b0\uff0c\u5e76\u4e8e\u00a02023 \u5e74 6 \u6708 1 \u65e5\u7ed3\u675f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5982\u679c\u4f60\u7684\u4ee3\u7801\u4f7f\u7528\u7684\u662f\u5b98\u65b9\u7684SDK\u9700\u8981\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\uff01\u6bd4\u5982Python OpenAI SDK \u5fc5\u987b\u66f4\u65b0\u52300.27.0\u4ee5\u4e0a\uff01<\/p>\n<p>\u6709\u4e9b\u955c\u50cf\u53ef\u80fd\u540c\u6b65\u4f1a\u6162\u4e00\u4e9b\uff0c\u53ef\u4ee5\u76f4\u63a5\u4ece\u5b98\u65b9\u66f4\u65b0\uff01<\/p>\n<pre class=\"corepress-code-pre\"><code class=\"hljs apache\"><\/code><\/pre>\n<ul class=\"hijs-line-number\">\n<li><span class=\"hljs-attribute\">pip3<\/span> install -i https:\/\/pypi.python.org\/simple\/ openai==<span class=\"hljs-number\">0<\/span>.<span class=\"hljs-number\">27<\/span>.<span class=\"hljs-number\">0<\/span><\/li>\n<\/ul>\n<pre class=\"corepress-code-pre\"><code class=\"hljs apache\"><\/code><\/pre>\n<div class=\"code-bar\"><\/div>\n<p>\u63a5\u53e3\u600e\u4e48\u8c03\u7528\uff1f<\/p>\n<p>&nbsp;<\/p>\n<p>\u5b98\u65b9DEMO<\/p>\n<pre class=\"corepress-code-pre\"><code class=\"hljs rust\"><\/code><\/pre>\n<ul class=\"hijs-line-number\">\n<li>curl https:<span class=\"hljs-comment\">\/\/api.openai.com\/v1\/chat\/completions \\<\/span><\/li>\n<li>-H <span class=\"hljs-symbol\">&#8216;Content<\/span>-Type: application\/json&#8217; \\<\/li>\n<li>-H <span class=\"hljs-symbol\">&#8216;Authorization<\/span>: Bearer YOUR_API_KEY&#8217; \\<\/li>\n<li>-d &#8216;{<\/li>\n<li><span class=\"hljs-string\">&#8220;model&#8221;<\/span>: <span class=\"hljs-string\">&#8220;gpt-3.5-turbo&#8221;<\/span>,<\/li>\n<li><span class=\"hljs-string\">&#8220;messages&#8221;<\/span>: [{<span class=\"hljs-string\">&#8220;role&#8221;<\/span>: <span class=\"hljs-string\">&#8220;user&#8221;<\/span>, <span class=\"hljs-string\">&#8220;content&#8221;<\/span>: <span class=\"hljs-string\">&#8220;Hello!&#8221;<\/span>}]<\/li>\n<li>}&#8217;<\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"corepress-code-pre\"><code class=\"hljs rust\"><\/code><\/pre>\n<div class=\"code-bar\"><\/div>\n<p>&nbsp;<\/p>\n<p>\u76f8\u5bf9\u4e8eGPT-3\u7684\u8c03\u7528\uff0c\u67092\u5904\u4e0d\u4e00\u6837<\/p>\n<ul>\n<li>\u63a5\u53e3\u5730\u5740<\/li>\n<li>\u53c2\u6570prompt \u6362\u6210 messages<\/li>\n<\/ul>\n<p>messages\u7684\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre class=\"corepress-code-pre\"><code class=\"hljs swift\"><\/code><\/pre>\n<ul class=\"hijs-line-number\">\n<li><span class=\"hljs-keyword\">import<\/span> openai<\/li>\n<li><\/li>\n<li>openai.<span class=\"hljs-type\">ChatCompletion<\/span>.create(<\/li>\n<li>model=<span class=\"hljs-string\">&#8220;gpt-3.5-turbo&#8221;<\/span>,<\/li>\n<li>messages=[<\/li>\n<li>{<span class=\"hljs-string\">&#8220;role&#8221;<\/span>: <span class=\"hljs-string\">&#8220;system&#8221;<\/span>, <span class=\"hljs-string\">&#8220;content&#8221;<\/span>: <span class=\"hljs-string\">&#8220;You are a helpful assistant.&#8221;<\/span>},<\/li>\n<li>{<span class=\"hljs-string\">&#8220;role&#8221;<\/span>: <span class=\"hljs-string\">&#8220;user&#8221;<\/span>, <span class=\"hljs-string\">&#8220;content&#8221;<\/span>: <span class=\"hljs-string\">&#8220;Who won the world series in 2020?&#8221;<\/span>},<\/li>\n<li>{<span class=\"hljs-string\">&#8220;role&#8221;<\/span>: <span class=\"hljs-string\">&#8220;assistant&#8221;<\/span>, <span class=\"hljs-string\">&#8220;content&#8221;<\/span>: <span class=\"hljs-string\">&#8220;The Los Angeles Dodgers won the World Series in 2020.&#8221;<\/span>},<\/li>\n<li>{<span class=\"hljs-string\">&#8220;role&#8221;<\/span>: <span class=\"hljs-string\">&#8220;user&#8221;<\/span>, <span class=\"hljs-string\">&#8220;content&#8221;<\/span>: <span class=\"hljs-string\">&#8220;Where was it played?&#8221;<\/span>}<\/li>\n<li>]<\/li>\n<li>)<\/li>\n<\/ul>\n<pre class=\"corepress-code-pre\"><code class=\"hljs swift\"><\/code><\/pre>\n<div class=\"code-bar\"><\/div>\n<p>&nbsp;<\/p>\n<p>messages\u91cc\u9762\u662f\u4e00\u4e2a\u5217\u8868\u3002\u5217\u8868\u7684\u6bcf\u4e00\u9879\u662f\u5b57\u5178\u3002<\/p>\n<p>\u5176\u4e2drole \u6709\u4e09\u79cd\u89d2\u8272\uff1asystem\uff0cuser\uff0cassistant<\/p>\n<p>system\uff0c\u4e00\u822c\u662f\u6d88\u606f\u7684\u7b2c\u4e00\u6761\uff0c\u5b9a\u4e00\u4e2a\u8fd9\u6b21\u4ea4\u4e92\u7684\u57fa\u8c03\u3002\u6bd4\u5982\u8fd9\u662f\u4e00\u4e2a\u7ffb\u8bd1\u7684AI\uff0c\u8fd9\u662f\u4e00\u4e2a\u4ee3\u7801\u52a9\u624b\u7b49\u7b49<\/p>\n<p>user\uff0c\u6307\u7684\u662f\u5b8c\u7f8e\u7528\u6237\u63d0\u5230\u7684\u95ee\u9898<\/p>\n<p>assistant\uff0c\u6307\u7684\u662fAI\u56de\u590d\u7684\u5185\u5bb9<\/p>\n<p>\u8fd9\u91cc\u5217\u8868\u987a\u5e8f\u9700\u8981\u6309\u7167\u63d0\u95ee\u56de\u7b54\u7684\u987a\u5e8f\u4f9d\u6b21\u6dfb\u52a0\uff01<\/p>\n<p>\u4e0b\u56fe\u662f3\u67082\u65e5\u65e9\u4e0a\u6d4b\u8bd5\u63a5\u53e3\u7684\u5185\u5bb9<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1700\" title=\"dc4d74d4a9daf4637098264aa46a8088\" src=\"https:\/\/oimi.me\/wp-content\/uploads\/2023\/03\/dc4d74d4a9daf4637098264aa46a8088.png\" alt=\"dc4d74d4a9daf4637098264aa46a8088\" width=\"1381\" height=\"648\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"catalog-h2-3\">\u4ee3\u7801\u5347\u7ea7<\/h2>\n<p>GPT-3 \u600e\u4e48\u65e0\u7f1d\u5207\u6362\u5230 GPT-3.5\uff1f\u5176\u5b9e\u4e5f\u7b80\u5355\uff0c\u5c31\u8c03\u6574\u4e00\u4e0b\u53c2\u6570\u5373\u53ef\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1701\" title=\"7251e4b9310c557e29b4a03a333084f5\" src=\"https:\/\/oimi.me\/wp-content\/uploads\/2023\/03\/7251e4b9310c557e29b4a03a333084f5.png\" alt=\"7251e4b9310c557e29b4a03a333084f5\" width=\"1158\" height=\"627\" \/><\/p>\n<p>\u4ec5\u9700\u56de\u590d\u673a\u5668\u4eba\u7684\u65f6\u5019\uff0c\u5f15\u7528\u5386\u53f2\u5e16\u5b50\u5373\u53ef\uff01<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"catalog-h2-4\">\u5f00\u6e90\u4ed3\u5e93<\/h2>\n<p>https:\/\/github.com\/malaohu\/nodebb-openai-chatgpt<\/p>\n<p>\u535a\u4e3b\u5df2\u7ecf\u5c06\u4ee3\u7801\u4e0a\u4f20\u5230Github\uff0c\u611f\u5174\u8da3\u7684\u7ae5\u978b\u53ef\u4ee5\u8bd5\u4e00\u8bd5\uff01<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"catalog-h2-5\">\u57df\u540d\u88ab\u5899<\/h2>\n<p>\u5c31\u57283\u67082\u65e5\u51cc\u6668\u8c03\u8bd5\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u7a81\u7136\u53d1\u73b0OpenAI\u7684API\u57df\u540d\u7591\u4f3c\u88abQ~<\/p>\n<p>\u540e\u6765\u67e5\u8be2\u4e00\u770b\uff0c\u679c\u7136~~~~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1703\" title=\"e19e64b01060c08fb7f1e3cb24aaf4da\" src=\"https:\/\/oimi.me\/wp-content\/uploads\/2023\/03\/e19e64b01060c08fb7f1e3cb24aaf4da.png\" alt=\"e19e64b01060c08fb7f1e3cb24aaf4da\" width=\"1280\" height=\"789\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"catalog-h2-6\">\u89e3\u51b3\u65b9\u6cd5<\/h2>\n<ul>\n<li>\u5c06\u4ee3\u7801\u670d\u52a1\u8fd0\u884c\u5728\u5883\u5916\u670d\u52a1\u5668\u4e0a\u3002<\/li>\n<li>\u56fd\u5185\u670d\u52a1\u5668\u6216\u8005\u4f60\u672c\u673a\uff0c\u9700\u8981\u524d\u7f6e\u4e00\u4e2a\u4ee3\u7406\u3002\u4e3e\u4e00\u53cd\u4e09\uff01<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1702\" title=\"3c7b646b51883baa348c713825f0ce55\" src=\"https:\/\/oimi.me\/wp-content\/uploads\/2023\/03\/3c7b646b51883baa348c713825f0ce55.png\" alt=\"3c7b646b51883baa348c713825f0ce55\" width=\"746\" height=\"146\" \/><\/p>\n<ul>\n<li>\u5883\u5916\u670d\u52a1\u5668\u53cd\u4ee3OpenAI API\u57df\u540d\uff0c\u5e94\u8be5\u4e5f\u6709\u4eba\u4f1a\u63d0\u4f9b\u8fd9\u6837\u7684\u670d\u52a1\u3002\u8fd9\u79cd\u60c5\u51b5\u6709\u5229\u6709\u5f0a\uff0c\u5c3d\u91cf\u8fd8\u662f\u81ea\u5efa\uff01\u6bd4\u5982\u4e0b\u9762\u7684Nginx\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<pre class=\"corepress-code-pre\"><code class=\"hljs nginx\"><\/code><\/pre>\n<ul class=\"hijs-line-number\">\n<li><span class=\"hljs-section\">server<\/span><\/li>\n<li>{<\/li>\n<li><span class=\"hljs-attribute\">listen<\/span> <span class=\"hljs-number\">8088<\/span>;<\/li>\n<li><span class=\"hljs-attribute\">server_name<\/span> _;<\/li>\n<li><span class=\"hljs-attribute\">location<\/span> \/ {<\/li>\n<li><span class=\"hljs-attribute\">proxy_redirect<\/span> <span class=\"hljs-literal\">off<\/span>;<\/li>\n<li><span class=\"hljs-attribute\">proxy_set_header<\/span> Host <span class=\"hljs-variable\">$host<\/span>;<\/li>\n<li><span class=\"hljs-attribute\">proxy_set_header<\/span> X-Real-IP <span class=\"hljs-variable\">$remote_addr<\/span>;<\/li>\n<li><span class=\"hljs-attribute\">proxy_set_header<\/span> X-Forwarded-For <span class=\"hljs-variable\">$proxy_add_x_forwarded_for<\/span>;<\/li>\n<li><span class=\"hljs-attribute\">proxy_pass<\/span> https:\/\/api.openai.com;<\/li>\n<li>}<\/li>\n<li><span class=\"hljs-attribute\">access_log<\/span> logs\/abccom.log;<\/li>\n<li>}<\/li>\n<\/ul>\n<pre class=\"corepress-code-pre\"><code class=\"hljs nginx\"><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>OpenAI \u5728\u7f8e\u56fd\u65f6\u95f43\u67081\u65e5\u6b63\u5f0f\u5f00\u653e\u4e86ChatGPT\u6a21\u578bGPT3.5\u7684API\u3002\u4e00\u4e0b\u5b50\u5927\u5bb6\u6709\u5fd9\u6d3b\u8d77\u6765\u4e86\uff01 \u535a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1702,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1699","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apple"],"_links":{"self":[{"href":"https:\/\/myya.net\/index.php\/wp-json\/wp\/v2\/posts\/1699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myya.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myya.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myya.net\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/myya.net\/index.php\/wp-json\/wp\/v2\/comments?post=1699"}],"version-history":[{"count":0,"href":"https:\/\/myya.net\/index.php\/wp-json\/wp\/v2\/posts\/1699\/revisions"}],"wp:attachment":[{"href":"https:\/\/myya.net\/index.php\/wp-json\/wp\/v2\/media?parent=1699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myya.net\/index.php\/wp-json\/wp\/v2\/categories?post=1699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myya.net\/index.php\/wp-json\/wp\/v2\/tags?post=1699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}