{"id":7253,"date":"2024-10-18T23:46:05","date_gmt":"2024-10-18T15:46:05","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=7253"},"modified":"2024-10-18T23:46:05","modified_gmt":"2024-10-18T15:46:05","slug":"one-api","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/pt\/one-api\/","title":{"rendered":"One API\uff1a\u591a\u6a21\u578bAPI\u7ba1\u7406\u4e0e\u8d1f\u8f7d\u5747\u8861,\u5206\u53d1\u7cfb\u7edf"},"content":{"rendered":"<p>One API \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u63a5\u53e3\u7ba1\u7406\u4e0e\u5206\u53d1\u7cfb\u7edf\uff0c\u652f\u6301\u591a\u79cd\u5927\u6a21\u578b\u5982 OpenAI ChatGPT\u3001Anthropic Claude\u3001Google PaLM 2 &amp; <a href=\"https:\/\/www.kdjingpai.com\/ja\/geminibardgubu\/\">Gemini<\/a> \u7b49\u3002\u8be5\u7cfb\u7edf\u901a\u8fc7\u6807\u51c6\u7684 OpenAI API \u683c\u5f0f\u8bbf\u95ee\u6240\u6709\u7684\u5927\u6a21\u578b\uff0c\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\u3001\u4ee4\u724c\u7ba1\u7406\u3001\u5151\u6362\u7801\u7ba1\u7406\u3001\u6e20\u9053\u7ba1\u7406\u7b49\u529f\u80fd\u3002\u7528\u6237\u53ef\u4ee5\u901a\u8fc7 Docker \u5feb\u901f\u90e8\u7f72\u548c\u4f7f\u7528 One API\uff0c\u5f00\u7bb1\u5373\u7528\u3002<\/p>\n<blockquote><p><a href=\"https:\/\/github.com\/Calcium-Ion\/new-api\">New API<\/a> \u57fa\u4e8eOne API\u7684\u4e8c\u6b21\u5f00\u53d1\u7248\u672c\uff0c\u652f\u6301Midjourney\u3002\u652f\u6301\u652f\u4ed8\u548c\u6309\u6a21\u578b\u4f7f\u7528\u6b21\u6570\u6536\u8d39\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/MartialBE\/one-api\">one api\u5206\u652f<\/a>\uff1a\u6539\u81easongquanpeng\/one-api\u3002\u652f\u6301\u66f4\u591a\u6a21\u578b\uff0c\u52a0\u5165\u7edf\u8ba1\u9875\u9762\uff0c\u5b8c\u5584\u975eopenai\u6a21\u578b\u7684\u51fd\u6570\u8c03\u7528\u3002<\/p><\/blockquote>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7254\" title=\"One API\uff1a\u591a\u6a21\u578bAPI\u7ba1\u7406\u4e0e\u8d1f\u8f7d\u5747\u8861,\u5206\u53d1\u7cfb\u7edf-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/32d52c118ef8225.png\" alt=\"One API\uff1a\u591a\u6a21\u578bAPI\u7ba1\u7406\u4e0e\u8d1f\u8f7d\u5747\u8861,\u5206\u53d1\u7cfb\u7edf-1\" width=\"1920\" height=\"991\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/32d52c118ef8225.png 1920w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/32d52c118ef8225-300x155.png 300w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/32d52c118ef8225-1024x529.png 1024w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/32d52c118ef8225-768x396.png 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/32d52c118ef8225-1536x793.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u529f\u80fd\u5217\u8868<\/h2>\n<ul>\n<li>\u83b7\u53d6\u548c\u7ba1\u7406\u591a\u79cd\u5927\u6a21\u578b\u7684API\u63a5\u53e3\uff1aAzure\u3001OpenAI ChatGPT\u3001Anthropic Claude\u3001Google PaLM 2 &amp; Gemini \u7b49<\/li>\n<li>\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\u529f\u80fd\uff0c\u652f\u6301\u591a\u4e2a\u6e20\u9053\u7684\u8bbf\u95ee<\/li>\n<li>\u5355\u4e00API\u6574\u5408\u4e0d\u540c\u7684\u8bed\u8a00\u6a21\u578b\u63a5\u53e3<\/li>\n<li>\u4ee4\u724c\u7ba1\u7406\uff1a\u8bbe\u7f6e\u4ee4\u724c\u7684\u8fc7\u671f\u65f6\u95f4\u3001\u989d\u5ea6\u3001\u5141\u8bb8\u7684 IP \u8303\u56f4\u53ca\u6a21\u578b\u8bbf\u95ee\u6743\u9650<\/li>\n<li>\u5151\u6362\u7801\u7ba1\u7406\uff1a\u6279\u91cf\u751f\u6210\u548c\u5bfc\u51fa\u5151\u6362\u7801\uff0c\u4e3a\u8d26\u6237\u5145\u503c<\/li>\n<li>\u6e20\u9053\u7ba1\u7406\uff1a\u6279\u91cf\u521b\u5efa\u6e20\u9053\uff0c\u8bbe\u7f6e\u6a21\u578b\u5217\u8868<\/li>\n<li>\u7528\u6237\u5206\u7ec4\u53ca\u6e20\u9053\u5206\u7ec4\u7ba1\u7406<\/li>\n<li>\u67e5\u770b\u989d\u5ea6\u660e\u7ec6\u53ca\u7528\u6237\u9080\u8bf7\u5956\u52b1<\/li>\n<li>\u652f\u6301\u7ed8\u56fe\u63a5\u53e3\u53ca Cloudflare AI Gateway<\/li>\n<li>\u81ea\u5b9a\u4e49\u7cfb\u7edf\u540d\u79f0\u3001logo \u53ca\u9875\u811a<\/li>\n<li>\u652f\u6301\u591a\u79cd\u7528\u6237\u767b\u5f55\u6ce8\u518c\u65b9\u5f0f\uff1a\u90ae\u7bb1\u3001\u98de\u4e66\u3001GitHub\u3001\u5fae\u4fe1\u516c\u4f17\u53f7<\/li>\n<li>\u652f\u6301Docker\u955c\u50cf\uff0c\u5b9e\u73b0\u4e00\u952e\u90e8\u7f72<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u4f7f\u7528\u5e2e\u52a9<\/h2>\n<h3>\u5b89\u88c5\u4e0e\u90e8\u7f72<\/h3>\n<p>One API \u652f\u6301\u901a\u8fc7 Docker \u8fdb\u884c\u5feb\u901f\u90e8\u7f72\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 SQLite \u548c MySQL \u7684\u90e8\u7f72\u547d\u4ee4\uff1a<\/p>\n<p><strong>\u4f7f\u7528 SQLite \u7684\u90e8\u7f72\u547d\u4ee4\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">docker run --name one-api -d --restart always -p 3000:3000 -e TZ=Asia\/Shanghai -v \/home\/ubuntu\/data\/one-api:\/data justsong\/one-api\r\n<\/code><\/pre>\n<p><strong>\u4f7f\u7528 MySQL \u7684\u90e8\u7f72\u547d\u4ee4\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">docker run --name one-api -d --restart always -p 3000:3000 -e SQL_DSN=<span class=\"hljs-string\">\"root:123456@tcp(localhost:3306)\/oneapi\"<\/span> -e TZ=Asia\/Shanghai -v \/home\/ubuntu\/data\/one-api:\/data justsong\/one-api\r\n<\/code><\/pre>\n<p>\u8bf7\u6839\u636e\u9700\u8981\u4fee\u6539\u6570\u636e\u5e93\u8fde\u63a5\u53c2\u6570\u3002<\/p>\n<h3>\u529f\u80fd\u64cd\u4f5c\u6307\u5357<\/h3>\n<ol>\n<li><strong>\u4ee4\u724c\u7ba1\u7406<\/strong>\uff1a\u5728\u7ba1\u7406\u754c\u9762\u4e2d\uff0c\u7528\u6237\u53ef\u4ee5\u8bbe\u7f6e\u4ee4\u724c\u7684\u8fc7\u671f\u65f6\u95f4\u3001\u989d\u5ea6\u3001\u5141\u8bb8\u7684 IP \u8303\u56f4\u53ca\u6a21\u578b\u8bbf\u95ee\u6743\u9650\u3002<\/li>\n<li><strong>\u5151\u6362\u7801\u7ba1\u7406<\/strong>\uff1a\u652f\u6301\u6279\u91cf\u751f\u6210\u548c\u5bfc\u51fa\u5151\u6362\u7801\uff0c\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u5151\u6362\u7801\u4e3a\u8d26\u6237\u5145\u503c\u3002<\/li>\n<li><strong>\u6e20\u9053\u7ba1\u7406<\/strong>\uff1a\u7528\u6237\u53ef\u4ee5\u6279\u91cf\u521b\u5efa\u6e20\u9053\uff0c\u5e76\u4e3a\u4e0d\u540c\u6e20\u9053\u8bbe\u7f6e\u6a21\u578b\u5217\u8868\u3002<\/li>\n<li><strong>\u7528\u6237\u5206\u7ec4\u53ca\u6e20\u9053\u5206\u7ec4<\/strong>\uff1a\u652f\u6301\u4e3a\u4e0d\u540c\u5206\u7ec4\u8bbe\u7f6e\u4e0d\u540c\u7684\u500d\u7387\uff0c\u65b9\u4fbf\u7ba1\u7406\u3002<\/li>\n<li><strong>\u67e5\u770b\u989d\u5ea6\u660e\u7ec6<\/strong>\uff1a\u7528\u6237\u53ef\u4ee5\u67e5\u770b\u8be6\u7ec6\u7684\u989d\u5ea6\u4f7f\u7528\u60c5\u51b5\u3002<\/li>\n<li><strong>\u7528\u6237\u9080\u8bf7\u5956\u52b1<\/strong>\uff1a\u901a\u8fc7\u9080\u8bf7\u65b0\u7528\u6237\uff0c\u83b7\u5f97\u5956\u52b1\u989d\u5ea6\u3002<\/li>\n<li><strong>\u81ea\u5b9a\u4e49\u8bbe\u7f6e<\/strong>\uff1a\u7528\u6237\u53ef\u4ee5\u81ea\u5b9a\u4e49\u7cfb\u7edf\u540d\u79f0\u3001logo \u53ca\u9875\u811a\uff0c\u751a\u81f3\u53ef\u4ee5\u81ea\u5b9a\u4e49\u9996\u9875\u548c\u5173\u4e8e\u9875\u9762\u3002<\/li>\n<\/ol>\n<h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n<p>\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u8c03\u7528 One API\uff1a<\/p>\n<pre><code class=\"language-python\"><span class=\"hljs-keyword\">import<\/span> requests\r\n\r\nurl = <span class=\"hljs-string\">\"http:\/\/localhost:3000\/v1\/completions\"<\/span>\r\nheaders = {\r\n    <span class=\"hljs-string\">\"Authorization\"<\/span>: <span class=\"hljs-string\">\"Bearer YOUR_API_KEY\"<\/span>,\r\n    <span class=\"hljs-string\">\"Content-Type\"<\/span>: <span class=\"hljs-string\">\"application\/json\"<\/span>\r\n}\r\ndata = {\r\n    <span class=\"hljs-string\">\"model\"<\/span>: <span class=\"hljs-string\">\"gpt-3.5-turbo\"<\/span>,\r\n    <span class=\"hljs-string\">\"prompt\"<\/span>: <span class=\"hljs-string\">\"Hello, world!\"<\/span>,\r\n    <span class=\"hljs-string\">\"max_tokens\"<\/span>: <span class=\"hljs-number\">50<\/span>\r\n}\r\n\r\nresponse = requests.post(url, headers=headers, json=data)\r\n<span class=\"hljs-built_in\">print<\/span>(response.json())\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>One API \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u63a5\u53e3\u7ba1\u7406\u4e0e\u5206\u53d1\u7cfb\u7edf\uff0c\u652f\u6301\u591a\u79cd\u5927\u6a21\u578b\u5982 OpenAI ChatGPT\u3001Anthropic Claude\u3001Google PaLM 2 &amp; Gemini \u7b49\u3002\u8be5\u7cfb\u7edf\u901a\u8fc7\u6807\u51c6\u7684 OpenAI API \u683c\u5f0f\u8bbf\u95ee\u6240\u6709&#8230;<\/p>\n","protected":false},"author":1,"featured_media":61126,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[230],"class_list":["post-7253","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tool","tag-aikaiyuanxiangmu"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/7253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/comments?post=7253"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/7253\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/media\/61126"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/media?parent=7253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/categories?post=7253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/tags?post=7253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}