extonlawrence commited on
Commit
29c2cb3
·
1 Parent(s): c326265

Retrieve and apply current persona prompt dynamically when generating messages

Browse files
src/routes/conversation/[id]/+server.ts CHANGED
@@ -442,6 +442,23 @@ export async function POST({ request, locals, params, getClientAddress }) {
442
  let hasError = false;
443
  const initialMessageContent = messageToWriteTo.content;
444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
  try {
446
  const ctx: TextGenerationContext = {
447
  model,
@@ -454,11 +471,7 @@ export async function POST({ request, locals, params, getClientAddress }) {
454
  ip: getClientAddress(),
455
  username: locals.user?.username,
456
  // Force-enable multimodal if user settings say so for this model
457
- forceMultimodal: Boolean(
458
- (await collections.settings.findOne(authCondition(locals)))?.multimodalOverrides?.[
459
- model.id
460
- ]
461
- ),
462
  };
463
  // run the text generation and send updates to the client
464
  for await (const event of textGeneration(ctx)) await update(event);
@@ -542,9 +555,7 @@ export async function PATCH({ request, locals, params }) {
542
 
543
  // Only include defined values in the update, with title sanitized
544
  const updateValues = {
545
- ...(values.title !== undefined && {
546
- title: values.title.replace(/<\/?think>/gi, "").trim(),
547
- }),
548
  ...(values.model !== undefined && { model: values.model }),
549
  };
550
 
 
442
  let hasError = false;
443
  const initialMessageContent = messageToWriteTo.content;
444
 
445
+ // Get current persona definition (may have been updated since conversation creation)
446
+ const userSettings = await collections.settings.findOne(authCondition(locals));
447
+ const personaId = conv.personaId ?? userSettings?.activePersona ?? "default-neutral";
448
+ const currentPersona = userSettings?.personas?.find((p) => p.id === personaId);
449
+
450
+ // Use current persona prompt (reflects any edits)
451
+ const preprompt = currentPersona?.prompt ?? conv.preprompt ?? "";
452
+
453
+ // Update conversation's preprompt to reflect current persona
454
+ await collections.conversations.updateOne(
455
+ { _id: conv._id },
456
+ { $set: { preprompt, updatedAt: new Date() } }
457
+ );
458
+
459
+ // Update conv object with current preprompt
460
+ conv.preprompt = preprompt;
461
+
462
  try {
463
  const ctx: TextGenerationContext = {
464
  model,
 
471
  ip: getClientAddress(),
472
  username: locals.user?.username,
473
  // Force-enable multimodal if user settings say so for this model
474
+ forceMultimodal: Boolean(userSettings?.multimodalOverrides?.[model.id]),
 
 
 
 
475
  };
476
  // run the text generation and send updates to the client
477
  for await (const event of textGeneration(ctx)) await update(event);
 
555
 
556
  // Only include defined values in the update, with title sanitized
557
  const updateValues = {
558
+ ...(values.title !== undefined && { title: values.title.replace(/<\/?think>/gi, "").trim() }),
 
 
559
  ...(values.model !== undefined && { model: values.model }),
560
  };
561