From 6eb4429523c0d5472622e8967de84ebcd1320b18 Mon Sep 17 00:00:00 2001 From: Joseph J Helfenbein Date: Sun, 26 Jan 2025 06:55:03 -0500 Subject: [PATCH] use different endpoint structure --- src/app/api/chat/route.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/app/api/chat/route.js b/src/app/api/chat/route.js index dd6c531..692cc9c 100644 --- a/src/app/api/chat/route.js +++ b/src/app/api/chat/route.js @@ -1,23 +1,19 @@ import { HuggingFaceInference } from "@langchain/community/llms/hf"; -export default async function handler(req, res) { - if (req.method === 'POST') { - try { - const { query } = req.body; +export async function POST(req, res) { + try { + const { query } = req.body; - const model = new HuggingFaceInference({ - model: 'm42-health/Llama3-Med42-8B', - apiKey: process.env.HUGGING_FACE_API_KEY, - }); + const model = new HuggingFaceInference({ + model: 'm42-health/Llama3-Med42-8B', + apiKey: process.env.HUGGING_FACE_API_KEY, + }); - const response = await model.invoke(query); + const response = await model.invoke(query); - res.status(200).json({ answer: response }); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Error generating response' }); - } - } else { - res.status(405).json({ error: 'Method Not Allowed' }); + res.status(200).json({ answer: response }); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Error generating response' }); } }