Files

1 line
1.4 KiB
JSON

{"repo": "aygemuy/whatsapp-bot", "files": {"api/ai/closeai.js": {"d4bf9b3a9749f6cfbc04d1bbe3f8304bdee821c5": {"t": 1785768932.9284852, "n": 1199, "h": "b5a1a717e99b9230", "c": "import fetch from \"node-fetch\";\nimport crypto from \"crypto\";\nconst API_BASE = [\n \"https://api.closeai-proxy.xyz\",\n \"https://api.openai-proxy.live\",\n];\nconst API_KEY = \"sk-zaTFbMjIUsKv23JlrhbyYdJG6A9gNOK2G713GvoZ0TBRkfI3\";\nconst MODEL_3_5 = \"gpt-3.5-turbo\";\nconst MODEL_4 = \"gpt-4\";\nconst closeai = async (model, messages, useSecondAPI = false) => {\n const url = useSecondAPI ? API_BASE[1] : API_BASE[0];\n try {\n const response = await fetch(`${url}/v1/chat/completions`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${API_KEY}`,\n },\n body: JSON.stringify({\n model: model,\n stream: true,\n temperature: 0,\n top_p: 0,\n messages: messages,\n }),\n });\n const decodedData = await response.text();\n return decodedData\n .split(\"\\n\")\n .filter((line) => \"\" !== line.trim())\n .map((line) => line.replace(\"data: \", \"\"))\n .slice(0, -1)\n .map((item) => JSON.parse(item))\n .map((v) => v.choices[0]?.delta.content)\n .join(\"\");\n } catch (error) {\n throw new Error(\"Fetch completion failed: \" + error.message);\n }\n};\nexport default closeai;\n"}}}}