factored-out system prompts into their own functions
This commit is contained in:
+27
-27
@@ -21,6 +21,26 @@ import { db } from "../../database/postgres";
|
|||||||
import type { ConversationsId } from "../../database/generated/public/Conversations";
|
import type { ConversationsId } from "../../database/generated/public/Conversations";
|
||||||
import type { UsersId } from "../../database/generated/public/Users";
|
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({
|
const openrouter = createOpenRouter({
|
||||||
apiKey: env.OPENROUTER_API_KEY,
|
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 }
|
||||||
: {
|
: {
|
||||||
role: "system" as const,
|
role: "system" as const,
|
||||||
content: `${systemPrompt}
|
content: mainSystemPrompt({
|
||||||
|
systemPrompt,
|
||||||
This is a summary of the conversation so far, from your point-of-view (so "I" and "me" refer to you):
|
previousRunningSummary,
|
||||||
<running_summary>
|
}),
|
||||||
${previousRunningSummary}
|
|
||||||
</running_summary>
|
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
...messages.slice(previousRunningSummaryIndex + 1),
|
...messages.slice(previousRunningSummaryIndex + 1),
|
||||||
],
|
],
|
||||||
@@ -159,21 +176,6 @@ ${previousRunningSummary}
|
|||||||
tools: undefined,
|
tools: undefined,
|
||||||
...parameters,
|
...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,
|
/** 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
|
* 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
|
* be done *after* the model response, not before; because when we run a
|
||||||
@@ -199,11 +201,9 @@ ${previousRunningSummary}
|
|||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
role: "system" as const,
|
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.
|
content: runningSummarySystemPrompt({
|
||||||
<running_summary>
|
previousRunningSummary,
|
||||||
${previousRunningSummary}
|
}),
|
||||||
</running_summary>
|
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
...messages.slice(previousRunningSummaryIndex + 1),
|
...messages.slice(previousRunningSummaryIndex + 1),
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user