factored-out system prompts into their own functions

master
Avraham Sakal 3 months ago
parent 5cfc70632e
commit 1f80ad4ba9

@ -21,6 +21,26 @@ import { db } from "../../database/postgres";
import type { ConversationsId } from "../../database/generated/public/Conversations";
import type { UsersId } from "../../database/generated/public/Users";
const mainSystemPrompt = ({
systemPrompt,
previousRunningSummary,
}: { systemPrompt: string; previousRunningSummary: string }) => `${systemPrompt}
This is a summary of the conversation so far, from your point-of-view (so "I" and "me" refer to you):
<running_summary>
${previousRunningSummary}
</running_summary>
`;
const runningSummarySystemPrompt = ({
previousRunningSummary,
}: {
previousRunningSummary: string;
}) => `Given the following summary of a conversation, coupled with the messages exchanged since that summary was produced, produce a new summary of the conversation.
<running_summary>
${previousRunningSummary}
</running_summary>
`;
const openrouter = createOpenRouter({
apiKey: env.OPENROUTER_API_KEY,
});
@ -145,13 +165,10 @@ export const chat = router({
? { role: "system" as const, content: systemPrompt }
: {
role: "system" as const,
content: `${systemPrompt}
This is a summary of the conversation so far, from your point-of-view (so "I" and "me" refer to you):
<running_summary>
${previousRunningSummary}
</running_summary>
`,
content: mainSystemPrompt({
systemPrompt,
previousRunningSummary,
}),
},
...messages.slice(previousRunningSummaryIndex + 1),
],
@ -159,21 +176,6 @@ ${previousRunningSummary}
tools: undefined,
...parameters,
});
console.log("sent", [
previousRunningSummary === ""
? { role: "system" as const, content: systemPrompt }
: {
role: "system" as const,
content: `${systemPrompt}
This is a summary of the conversation so far, from your point-of-view (so "I" and "me" refer to you):
<running_summary>
${previousRunningSummary}
</running_summary>
`,
},
...messages.slice(previousRunningSummaryIndex + 1),
]);
/** Extract Facts from the user's message, and add them to the database,
* linking the Facts with the messages they came from. (Yes, this should
* be done *after* the model response, not before; because when we run a
@ -199,11 +201,9 @@ ${previousRunningSummary}
messages: [
{
role: "system" as const,
content: `Given the following summary of a conversation, coupled with the messages exchanged since that summary was produced, produce a new summary of the conversation.
<running_summary>
${previousRunningSummary}
</running_summary>
`,
content: runningSummarySystemPrompt({
previousRunningSummary,
}),
},
...messages.slice(previousRunningSummaryIndex + 1),
{

Loading…
Cancel
Save