Skip to content

Commit

Permalink
docs: q&a message pairs (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Aug 7, 2024
1 parent ae61f0c commit 8ed24a2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions apps/docs/app/api/entelligence/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8ed24a2

Please sign in to comment.