Skip to content

Commit

Permalink
Fix redir
Browse files Browse the repository at this point in the history
  • Loading branch information
DynamicApproach committed Sep 19, 2024
1 parent 91d7437 commit 488e031
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pages/api/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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 ?? "";
Expand All @@ -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." });
}
}

0 comments on commit 488e031

Please sign in to comment.