From 488e031254e75b4b7dae638bbaacfa6f915279fd Mon Sep 17 00:00:00 2001 From: DynamicApproach Date: Thu, 19 Sep 2024 17:56:01 -0400 Subject: [PATCH] Fix redir --- pages/api/map.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pages/api/map.js b/pages/api/map.js index 1691e54..eb99a7e 100644 --- a/pages/api/map.js +++ b/pages/api/map.js @@ -4,7 +4,7 @@ import OpenAI from "openai"; import { Transformer } from "markmap-lib"; const openai = new OpenAI({ - apiKey: process.env.OPENAI_API_KEY, + apiKey: process.env.OPENAI_API_KEY }); // Simple in-memory cache @@ -14,7 +14,11 @@ export default async function handler(req, res) { const { topic } = req.query; if (!topic || typeof topic !== "string") { - res.status(400).json({ error: "The \"topic\" query parameter is required and must be a string." }); + res + .status(400) + .json({ + error: "The \"topic\" query parameter is required and must be a string." + }); return; } @@ -33,7 +37,7 @@ export default async function handler(req, res) { const completion = await openai.chat.completions.create({ model: "gpt-4", messages: [{ role: "user", content: prompt }], - max_tokens: 2000, + max_tokens: 2000 }); const text = completion.choices[0]?.message?.content ?? ""; @@ -47,6 +51,8 @@ export default async function handler(req, res) { res.status(200).json({ mapData: root }); } catch (error) { console.error("Error generating map data:", error); - res.status(500).json({ error: "An error occurred while generating the map data." }); + res + .status(500) + .json({ error: "An error occurred while generating the map data." }); } }