From 045fa89053888221444c16044e698a0c40252e74 Mon Sep 17 00:00:00 2001 From: Joseph J Helfenbein Date: Sun, 26 Jan 2025 09:00:49 -0500 Subject: [PATCH] get correct text in json --- src/app/api/chat/route.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/api/chat/route.js b/src/app/api/chat/route.js index 27a8dd8..004e2d8 100644 --- a/src/app/api/chat/route.js +++ b/src/app/api/chat/route.js @@ -51,8 +51,10 @@ export async function POST(req) { ); } - const data = await response.text(); - return new Response(JSON.stringify({ answer: data }), { status: 200 }); + const data = await response.json(); + const answer = data?.choices?.[0]?.message?.content || "No answer found"; + + return new Response(JSON.stringify({ answer }), { status: 200 }); } catch (error) { console.error("Backend error:", error); return new Response(