From b25c29046333298c59f2738078a0da2233374cc4 Mon Sep 17 00:00:00 2001 From: Joseph J Helfenbein Date: Sun, 26 Jan 2025 07:17:12 -0500 Subject: [PATCH] fix endpoint --- src/app/api/chat/route.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/app/api/chat/route.js b/src/app/api/chat/route.js index 692cc9c..bc6ff2d 100644 --- a/src/app/api/chat/route.js +++ b/src/app/api/chat/route.js @@ -1,19 +1,24 @@ import { HuggingFaceInference } from "@langchain/community/llms/hf"; -export async function POST(req, res) { +export async function POST(req) { try { - const { query } = req.body; + const body = await req.json(); + const { query } = body; const model = new HuggingFaceInference({ - model: 'm42-health/Llama3-Med42-8B', + model: "m42-health/Llama3-Med42-8B", apiKey: process.env.HUGGING_FACE_API_KEY, }); const response = await model.invoke(query); - res.status(200).json({ answer: response }); + return new Response(JSON.stringify({ answer: response }), { + status: 200, + }); } catch (error) { - console.error(error); - res.status(500).json({ error: 'Error generating response' }); + console.error("Backend error:", error); + return new Response(JSON.stringify({ error: "Error generating response" }), { + status: 500, + }); } }