Skip to content

Commit

Permalink
feat: update to latest prompt template with {{question}}
Browse files Browse the repository at this point in the history
  • Loading branch information
marcklingen committed Nov 22, 2024
1 parent b88a063 commit eeb0148
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pages/api/qa-chatbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export default async function handler(req: Request, res: Response) {
role: role,
}));

// get last message
const sanitizedQuery = messages[messages.length - 1].content.trim();
// get the last user message and remove it from the array
const sanitizedQuery = openAiMessageHistory.pop().content.trim();

trace.update({
input: sanitizedQuery,
Expand Down Expand Up @@ -168,14 +168,16 @@ export default async function handler(req: Request, res: Response) {
});
const compiledLangfuseMessages = langfusePrompt.compile({
context: contextText,
question: sanitizedQuery,
});
promptSpan.end({
output: { compiledLangfuseMessages, version: langfusePrompt.version },
});

const assembledMessages = [
...compiledLangfuseMessages,
...openAiMessageHistory,
...compiledLangfuseMessages.slice(0, -1), // all system messages
...openAiMessageHistory, // history
compiledLangfuseMessages[compiledLangfuseMessages.length - 1], // last user message
];

const generation = trace.generation({
Expand Down

0 comments on commit eeb0148

Please sign in to comment.