{"id":1991,"date":"2024-04-23T03:03:58","date_gmt":"2024-04-22T19:03:58","guid":{"rendered":"https:\/\/www.tchepai.com\/?p=1991"},"modified":"2025-01-04T11:55:08","modified_gmt":"2025-01-04T03:55:08","slug":"nixiangapi","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/de\/nixiangapi\/","title":{"rendered":"\u6536\u96c6\u514d\u8d39\u5bf9\u8bdd\u5927\u6a21\u578b\u9006\u5411\u8f6cAPI\u63a5\u53e3"},"content":{"rendered":"<p><strong>\u514d\u8d39\u767b\u5f55 GPT3.5 \u8f6c API<\/strong><\/p>\n<p>https:\/\/github.com\/missuo\/FreeGPT35<\/p>\n<p>https:\/\/github.com\/aurora-develop\/aurora<\/p>\n<p>https:\/\/github.com\/Dalufishe\/freegptjs<\/p>\n<p>https:\/\/github.com\/PawanOsman\/ChatGPT<\/p>\n<p>https:\/\/github.com\/nashsu\/FreeAskInternet<\/p>\n<p>https:\/\/github.com\/aurorax-neo\/free-gpt3.5-2api<\/p>\n<p>https:\/\/github.com\/aurora-develop\/free-gpt3.5-2api<\/p>\n<p>https:\/\/github.com\/LanQian528\/chat2api<\/p>\n<p>https:\/\/github.com\/k0baya\/FreeGPT35-Glitch<\/p>\n<p>https:\/\/github.com\/cliouo\/FreeGPT35-Vercel<\/p>\n<p>https:\/\/github.com\/hominsu\/freegpt35<\/p>\n<p>https:\/\/github.com\/xsigoking\/chatgpt-free-api<\/p>\n<p>https:\/\/github.com\/skzhengkai\/free-chatgpt-api<\/p>\n<p>https:\/\/github.com\/aurora-develop\/aurora-glitch \uff08\u4f7f\u7528glitch\u8d44\u6e90\uff09<\/p>\n<p>https:\/\/github.com\/fatwang2\/coze2openai\uff08COZE\u8f6cAPI\uff0cGPT4\uff09<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u56fd\u4ea7\u6a21\u578b\u9006\u5411<\/strong><\/p>\n<p><a href=\"https:\/\/www.kdjingpai.com\/deepseek-chatshena\/\">\u6df1\u5ea6\u6c42\u7d22<\/a>\uff08DeepSeek\uff09\u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/deepseek-free-api\">deepseek-free-api<\/a><\/p>\n<p>Moonshot AI\uff08Kimi.ai\uff09\u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/kimi-free-api\">kimi-free-api<\/a><\/p>\n<p dir=\"auto\"><a href=\"https:\/\/www.kdjingpai.com\/stepchat\/\">\u9636\u8dc3\u661f\u8fb0<\/a> (\u8dc3\u95eeStepChat) \u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/step-free-api\">step-free-api<\/a><\/p>\n<p dir=\"auto\">\u963f\u91cc\u901a\u4e49 (Qwen) \u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/qwen-free-api\">qwen-free-api<\/a><\/p>\n<p dir=\"auto\">ZhipuAI (<a href=\"https:\/\/www.kdjingpai.com\/chatglm\/\">\u667a\u8c31\u6e05\u8a00<\/a>) \u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/glm-free-api\">glm-free-api<\/a><\/p>\n<p dir=\"auto\">\u79d8\u5854AI (metaso) \u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/metaso-free-api\">metaso-free-api<\/a><\/p>\n<p dir=\"auto\">\u5b57\u8282\u8df3\u52a8\uff08\u8c46\u5305\uff09\u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/doubao-free-api\">doubao-free-api<\/a><\/p>\n<p dir=\"auto\">\u5b57\u8282\u8df3\u52a8\uff08\u5373\u68a6AI\uff09\u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/jimeng-free-api\">jimeng-free-api<\/a><\/p>\n<p dir=\"auto\">\u8baf\u98de\u661f\u706b\uff08Spark\uff09\u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/spark-free-api\">spark-free-api<\/a><\/p>\n<p dir=\"auto\">MiniMax\uff08\u6d77\u87baAI\uff09\u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/hailuo-free-api\">hailuo-free-api<\/a><\/p>\n<p dir=\"auto\">\u8046\u5fc3\u667a\u80fd (Emohaa) \u63a5\u53e3\u8f6cAPI\u00a0<a href=\"https:\/\/github.com\/LLM-Red-Team\/emohaa-free-api\">emohaa-free-api<\/a><\/p>\n<p dir=\"auto\"><strong>\u5e26\u6709\u804a\u5929\u754c\u9762\u7684\u514d\u767b\u5f55\u9879\u76ee<\/strong><\/p>\n<p>https:\/\/github.com\/Mylinde\/FreeGPT<\/p>\n<p>&nbsp;<\/p>\n<p><strong>cloudflare \u7684work\u4ee3\u7801\uff0c\u7ed1\u4e2a\u81ea\u5df1\u57df\u540d\u73a9\uff1a<\/strong><\/p>\n<blockquote><p>addEventListener(&#8220;fetch&#8221;, event =&gt; {<br \/>\nevent.respondWith(handleRequest(event.request))<br \/>\n})<\/p>\n<p>async function handleRequest(request) {<br \/>\n\/\/ \u786e\u4fdd\u8bf7\u6c42\u662f POST \u8bf7\u6c42\uff0c\u5e76\u4e14\u8def\u5f84\u6b63\u786e<br \/>\nif (request.method === &#8220;POST&#8221; &amp;&amp; new URL(request.url).pathname === &#8220;\/v1\/chat\/completions&#8221;) {<br \/>\nconst url = &#8216;https:\/\/multillm.ai-pro.org\/api\/openai-completion&#8217;; \/\/ \u76ee\u6807 API \u5730\u5740<br \/>\nconst headers = new Headers(request.headers);<\/p>\n<p>\/\/ \u6dfb\u52a0\u6216\u4fee\u6539\u9700\u8981\u7684 headers<br \/>\nheaders.set(&#8216;Content-Type&#8217;, &#8216;application\/json&#8217;);<\/p>\n<p>\/\/ \u83b7\u53d6\u8bf7\u6c42\u7684 body \u5e76\u89e3\u6790 JSON<br \/>\nconst requestBody = await request.json();<br \/>\nconst stream = requestBody.stream; \/\/ \u83b7\u53d6 stream \u53c2\u6570<\/p>\n<p>\/\/ \u6784\u9020\u65b0\u7684\u8bf7\u6c42<br \/>\nconst newRequest = new Request(url, {<br \/>\nmethod: &#8216;POST&#8217;,<br \/>\nheaders: headers,<br \/>\nbody: JSON.stringify(requestBody) \/\/ \u4f7f\u7528\u4fee\u6539\u540e\u7684 body<br \/>\n});<\/p>\n<p>try {<br \/>\n\/\/ \u5411\u76ee\u6807 API \u53d1\u9001\u8bf7\u6c42<br \/>\nconst response = await fetch(newRequest);<\/p>\n<p>\/\/ \u6839\u636e stream \u53c2\u6570\u786e\u5b9a\u54cd\u5e94\u7c7b\u578b<br \/>\nif (stream) {<br \/>\n\/\/ \u5904\u7406\u6d41\u5f0f\u54cd\u5e94<br \/>\nconst { readable, writable } = new TransformStream();<br \/>\nresponse.body.pipeTo(writable);<br \/>\nreturn new Response(readable, {<br \/>\nheaders: response.headers<br \/>\n});<br \/>\n} else {<br \/>\n\/\/ \u6b63\u5e38\u8fd4\u56de\u54cd\u5e94<br \/>\nreturn new Response(response.body, {<br \/>\nstatus: response.status,<br \/>\nheaders: response.headers<br \/>\n});<br \/>\n}<br \/>\n} catch (e) {<br \/>\n\/\/ \u5982\u679c\u8bf7\u6c42\u5931\u8d25\uff0c\u8fd4\u56de\u9519\u8bef\u4fe1\u606f<br \/>\nreturn new Response(JSON.stringify({ error: &#8216;Unable to reach the backend API&#8217; }), { status: 502 });<br \/>\n}<br \/>\n} else {<br \/>\n\/\/ \u5982\u679c\u8bf7\u6c42\u65b9\u6cd5\u4e0d\u662f POST \u6216\u8def\u5f84\u4e0d\u6b63\u786e\uff0c\u8fd4\u56de\u9519\u8bef<br \/>\nreturn new Response(&#8216;Not found&#8217;, { status: 404 });<br \/>\n}<br \/>\n}<\/p><\/blockquote>\n<p>POST\u793a\u4f8b\uff1a<\/p>\n<blockquote><p>curl &#8211;location &#8216;https:\/\/ai-pro-free.aivvm.com\/v1\/chat\/completions&#8217; \\<br \/>\n&#8211;header &#8216;Content-Type: application\/json&#8217; \\<br \/>\n&#8211;data &#8216;{<br \/>\n&#8220;model&#8221;: &#8220;gpt-4-turbo&#8221;,<br \/>\n&#8220;messages&#8221;: [<br \/>\n{<br \/>\n&#8220;role&#8221;: &#8220;user&#8221;, &#8220;content&#8221;: &#8220;\u9c81\u8fc5\u4e3a\u4ec0\u4e48\u6253\u5468\u6811\u4eba&#8221;<br \/>\n}],<br \/>\n&#8220;stream&#8221;: true<br \/>\n}&#8217;<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>\u52a0\u4e2a\u4f2a\u6d41\u5f0f\u4ee3\u7801\uff08\u8f93\u51fa\u4f1a\u66f4\u6162\uff09\uff1a<\/p>\n<blockquote><p>addEventListener(&#8220;fetch&#8221;, event =&gt; {<br \/>\nevent.respondWith(handleRequest(event.request))<br \/>\n})<\/p>\n<p>async function handleRequest(request) {<br \/>\nif (request.method === &#8220;OPTIONS&#8221;) {<br \/>\nreturn new Response(null, {<br \/>\nheaders: {<br \/>\n&#8216;Access-Control-Allow-Origin&#8217;: &#8216;*&#8217;,<br \/>\n&#8220;Access-Control-Allow-Headers&#8221;: &#8216;*&#8217;<br \/>\n}, status: 204<br \/>\n})<br \/>\n}<br \/>\n\/\/ \u786e\u4fdd\u8bf7\u6c42\u662f POST \u8bf7\u6c42\uff0c\u5e76\u4e14\u8def\u5f84\u6b63\u786e<br \/>\nif (request.method === &#8220;POST&#8221; &amp;&amp; new URL(request.url).pathname === &#8220;\/v1\/chat\/completions&#8221;) {<br \/>\nconst url = &#8216;https:\/\/multillm.ai-pro.org\/api\/openai-completion&#8217;; \/\/ \u76ee\u6807 API \u5730\u5740<br \/>\nconst headers = new Headers(request.headers);<\/p>\n<p>\/\/ \u6dfb\u52a0\u6216\u4fee\u6539\u9700\u8981\u7684 headers<br \/>\nheaders.set(&#8216;Content-Type&#8217;, &#8216;application\/json&#8217;);<\/p>\n<p>\/\/ \u83b7\u53d6\u8bf7\u6c42\u7684 body \u5e76\u89e3\u6790 JSON<br \/>\nconst requestBody = await request.json();<br \/>\nconst stream = requestBody.stream; \/\/ \u83b7\u53d6 stream \u53c2\u6570<\/p>\n<p>\/\/ \u6784\u9020\u65b0\u7684\u8bf7\u6c42<br \/>\nconst newRequest = new Request(url, {<br \/>\nmethod: &#8216;POST&#8217;,<br \/>\nheaders: headers,<br \/>\nbody: JSON.stringify(requestBody) \/\/ \u4f7f\u7528\u4fee\u6539\u540e\u7684 body<br \/>\n});<\/p>\n<p>try {<br \/>\n\/\/ \u5411\u76ee\u6807 API \u53d1\u9001\u8bf7\u6c42<br \/>\nconst response = await fetch(newRequest);<\/p>\n<p>\/\/ \u6839\u636e stream \u53c2\u6570\u786e\u5b9a\u54cd\u5e94\u7c7b\u578b<br \/>\nif (stream) {<br \/>\nconst originalJson = await response.json(); \/\/ \u4e00\u6b21\u6027\u8bfb\u53d6\u5b8c\u6574\u6570\u636e<br \/>\n\/\/ \u521b\u5efa\u4e00\u4e2a\u53ef\u8bfb\u6d41<br \/>\nconst readableStream = new ReadableStream({<br \/>\nstart(controller) {<br \/>\n\/\/ \u53d1\u9001\u5f00\u59cb\u6570\u636e<br \/>\nconst startData = createDataChunk(originalJson, &#8220;start&#8221;);<br \/>\ncontroller.enqueue(new TextEncoder().encode(&#8216;data: &#8216; + JSON.stringify(startData) + &#8216;\\n\\n&#8217;));<\/p>\n<p>\/\/ \u5047\u8bbe\u6839\u636e originalJson \u5904\u7406\u5e76\u53d1\u9001\u591a\u4e2a\u6570\u636e\u5757<br \/>\n\/\/ \u4f8b\u5982\uff0c\u6a21\u62df\u5206\u6279\u6b21\u53d1\u9001\u6570\u636e<br \/>\nconst content = originalJson.choices[0].message.content; \/\/ \u5047\u8bbe\u8fd9\u662f\u8981\u53d1\u9001\u7684\u5185\u5bb9<br \/>\nconst newData = createDataChunk(originalJson, &#8220;data&#8221;, content);<br \/>\ncontroller.enqueue(new TextEncoder().encode(&#8216;data: &#8216; + JSON.stringify(newData) + &#8216;\\n\\n&#8217;));<\/p>\n<p>\/\/ \u53d1\u9001\u7ed3\u675f\u6570\u636e<br \/>\nconst endData = createDataChunk(originalJson, &#8220;end&#8221;);<br \/>\ncontroller.enqueue(new TextEncoder().encode(&#8216;data: &#8216; + JSON.stringify(endData) + &#8216;\\n\\n&#8217;));<\/p>\n<p>controller.enqueue(new TextEncoder().encode(&#8216;data: [DONE]&#8217;));<br \/>\n\/\/ \u6807\u8bb0\u6d41\u7684\u7ed3\u675f<br \/>\ncontroller.close();<br \/>\n}<br \/>\n});<br \/>\nreturn new Response(readableStream, {<br \/>\nheaders: {<br \/>\n&#8216;Access-Control-Allow-Origin&#8217;: &#8216;*&#8217;,<br \/>\n&#8220;Access-Control-Allow-Headers&#8221;: &#8216;*&#8217;,<br \/>\n&#8216;Content-Type&#8217;: &#8216;text\/event-stream&#8217;,<br \/>\n&#8216;Cache-Control&#8217;: &#8216;no-cache&#8217;,<br \/>\n&#8216;Connection&#8217;: &#8216;keep-alive&#8217;<br \/>\n}<br \/>\n});<br \/>\n} else {<br \/>\n\/\/ \u6b63\u5e38\u8fd4\u56de\u54cd\u5e94<br \/>\nreturn new Response(response.body, {<br \/>\nstatus: response.status,<br \/>\nheaders: response.headers<br \/>\n});<br \/>\n}<br \/>\n} catch (e) {<br \/>\n\/\/ \u5982\u679c\u8bf7\u6c42\u5931\u8d25\uff0c\u8fd4\u56de\u9519\u8bef\u4fe1\u606f<br \/>\nreturn new Response(JSON.stringify({ error: &#8216;Unable to reach the backend API&#8217; }), { status: 502 });<br \/>\n}<br \/>\n} else {<br \/>\n\/\/ \u5982\u679c\u8bf7\u6c42\u65b9\u6cd5\u4e0d\u662f POST \u6216\u8def\u5f84\u4e0d\u6b63\u786e\uff0c\u8fd4\u56de\u9519\u8bef<br \/>\nreturn new Response(&#8216;Not found&#8217;, { status: 404 });<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ \u6839\u636e\u7c7b\u578b\u521b\u5efa\u4e0d\u540c\u7684\u6570\u636e\u5757<br \/>\nfunction createDataChunk(json, type, content = {}) {<br \/>\nswitch (type) {<br \/>\ncase &#8220;start&#8221;:<br \/>\nreturn {<br \/>\nid: json.id,<br \/>\nobject: &#8220;chat.completion.chunk&#8221;,<br \/>\ncreated: json.created,<br \/>\nmodel: json.model,<br \/>\nchoices: [{ delta: {}, index: 0, finish_reason: null }]<br \/>\n};<br \/>\ncase &#8220;data&#8221;:<br \/>\nreturn {<br \/>\nid: json.id,<br \/>\nobject: &#8220;chat.completion.chunk&#8221;,<br \/>\ncreated: json.created,<br \/>\nmodel: json.model,<br \/>\nchoices: [{ delta: { content }, index: 0, finish_reason: null }]<br \/>\n};<br \/>\ncase &#8220;end&#8221;:<br \/>\nreturn {<br \/>\nid: json.id,<br \/>\nobject: &#8220;chat.completion.chunk&#8221;,<br \/>\ncreated: json.created,<br \/>\nmodel: json.model,<br \/>\nchoices: [{ delta: {}, index: 0, finish_reason: &#8216;stop&#8217; }]<br \/>\n};<br \/>\ndefault:<br \/>\nreturn {};<br \/>\n}<br \/>\n}<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u514d\u8d39\u767b\u5f55 GPT3.5 \u8f6c API https:\/\/github.com\/missuo\/FreeGPT35 https:\/\/github.com\/aurora-develop\/aurora https:\/\/github.com\/Dalufi&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[255],"class_list":["post-1991","post","type-post","status-publish","format-standard","hentry","category-tool","tag-mianfeidamoxingapi"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/posts\/1991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/comments?post=1991"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/posts\/1991\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/media?parent=1991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/categories?post=1991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/tags?post=1991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}