1 line
4.5 KiB
JSON
1 line
4.5 KiB
JSON
{"repo": "aygemuy/api-wudysoft", "files": {"pages/api/ai/smart-chat.js": {"56d4429e439fed2bce629c3ba60042e343672edc": {"t": 1785747180.760287, "n": 2031, "h": "6cc069e8f78dfc07", "c": "import axios from \"axios\";\nclass SmartChat {\n constructor() {\n this.key = \"sk-8d134604d7b141168053714e79726b40\";\n this.url = \"https://iz8asbyu66.execute-api.us-east-1.amazonaws.com/prod/aichatbot\";\n this.sys = \"You are a helpful AI assistant. Answer the user's request clearly and concisely.\";\n }\n async chat({\n prompt,\n model = \"deepseek-v4-flash\",\n messages = [],\n ...rest\n }) {\n if (!this.key) return console.log(\"[ERR] Key missing.\"), null;\n try {\n if (!messages.length) {\n let systemInstruction = this.sys;\n if (!systemInstruction.toLowerCase().includes(\"reply in\")) {\n systemInstruction += \" Please reply in English.\";\n }\n messages.push({\n role: \"system\",\n content: systemInstruction\n });\n }\n if (prompt) messages.push({\n role: \"user\",\n content: prompt\n });\n const res = await axios.post(this.url, {\n model: model,\n temperature: .6,\n stream: false,\n messages: messages,\n ...rest\n }, {\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.key}`\n },\n timeout: 6e4\n });\n const msg = res.data?.choices?.[0]?.message;\n if (msg) messages.push(msg);\n return {\n ...res.data,\n messages: messages\n };\n } catch (err) {\n return console.log(`[ERR] ${err.response?.status || \"CONN\"} - ${err.message}`),\n null;\n }\n }\n}\nexport default async function handler(req, res) {\n const params = req.method === \"GET\" ? req.query : req.body;\n if (!params.prompt) {\n return res.status(400).json({\n error: \"Parameter 'prompt' diperlukan\"\n });\n }\n const api = new SmartChat();\n try {\n const data = await api.chat(params);\n return res.status(200).json(data);\n } catch (error) {\n const errorMessage = error.message || \"Terjadi kesalahan saat memproses request\";\n return res.status(500).json({\n error: errorMessage\n });\n }\n}"}, "c4741c0da28deef988f4bd32c614510b01d0c157": {"t": 1785771067.6348348, "n": 2031, "h": "6cc069e8f78dfc07", "c": "import axios from \"axios\";\nclass SmartChat {\n constructor() {\n this.key = \"sk-8d134604d7b141168053714e79726b40\";\n this.url = \"https://iz8asbyu66.execute-api.us-east-1.amazonaws.com/prod/aichatbot\";\n this.sys = \"You are a helpful AI assistant. Answer the user's request clearly and concisely.\";\n }\n async chat({\n prompt,\n model = \"deepseek-v4-flash\",\n messages = [],\n ...rest\n }) {\n if (!this.key) return console.log(\"[ERR] Key missing.\"), null;\n try {\n if (!messages.length) {\n let systemInstruction = this.sys;\n if (!systemInstruction.toLowerCase().includes(\"reply in\")) {\n systemInstruction += \" Please reply in English.\";\n }\n messages.push({\n role: \"system\",\n content: systemInstruction\n });\n }\n if (prompt) messages.push({\n role: \"user\",\n content: prompt\n });\n const res = await axios.post(this.url, {\n model: model,\n temperature: .6,\n stream: false,\n messages: messages,\n ...rest\n }, {\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.key}`\n },\n timeout: 6e4\n });\n const msg = res.data?.choices?.[0]?.message;\n if (msg) messages.push(msg);\n return {\n ...res.data,\n messages: messages\n };\n } catch (err) {\n return console.log(`[ERR] ${err.response?.status || \"CONN\"} - ${err.message}`),\n null;\n }\n }\n}\nexport default async function handler(req, res) {\n const params = req.method === \"GET\" ? req.query : req.body;\n if (!params.prompt) {\n return res.status(400).json({\n error: \"Parameter 'prompt' diperlukan\"\n });\n }\n const api = new SmartChat();\n try {\n const data = await api.chat(params);\n return res.status(200).json(data);\n } catch (error) {\n const errorMessage = error.message || \"Terjadi kesalahan saat memproses request\";\n return res.status(500).json({\n error: errorMessage\n });\n }\n}"}}}} |