From 8ed24a283bfb8a309db949bbff15d023e0c1d0ca Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Tue, 6 Aug 2024 23:28:57 -0700 Subject: [PATCH] docs: q&a message pairs (#659) --- apps/docs/app/api/entelligence/route.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/docs/app/api/entelligence/route.ts b/apps/docs/app/api/entelligence/route.ts index abf3135e0..5248a9e44 100644 --- a/apps/docs/app/api/entelligence/route.ts +++ b/apps/docs/app/api/entelligence/route.ts @@ -7,16 +7,24 @@ export const POST = async (req: Request) => { const { content: question, role } = messages.pop()!; if (role !== "user" || !question) throw new Error("No question provided"); + const history = messages.reduce( + (pairs, msg, i, arr) => { + const next = arr[i + 1]; + if (msg.role === "user" && next?.role === "assistant") { + pairs.push([msg.content, next.content]); + } + return pairs; + }, + [] as [string, string][], + ); + return fetch(process.env["ENTELLIGENCE_API_URL"]!, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ - history: messages.map((m) => ({ - role: m.role, - content: m.content, - })), + history, question, vectorDBUrl: "Yonom&assistant-ui", advancedAgent: false,