add hugging face call

This commit is contained in:
Joseph J Helfenbein
2025-01-26 06:33:14 -05:00
parent 6fbd80c3fb
commit 86e4b38090
3 changed files with 88 additions and 24 deletions

20
src/app/api/chat/route.js Normal file
View File

@@ -0,0 +1,20 @@
import { InferenceAPI } from '@huggingface/inference';
const hfAPI = new InferenceAPI({ apiKey: process.env.HUGGING_FACE_API_KEY });
export default async function handler(req, res) {
if (req.method === 'POST') {
try {
const { query } = req.body;
const response = await hfAPI.query('m42-health/Llama3-Med42-8B', { inputs: { text: query } });
res.status(200).json({ answer: response.data[0].generated_text });
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Error generating response' });
}
} else {
res.status(405).json({ error: 'Method Not Allowed' });
}
}