fix: skip default rule reminder when story has custom narrativeRules
This commit is contained in:
@@ -267,6 +267,7 @@ ${story.plot}`;
|
|||||||
export function buildDynamicContext(
|
export function buildDynamicContext(
|
||||||
session: GameSession,
|
session: GameSession,
|
||||||
messageCount?: number,
|
messageCount?: number,
|
||||||
|
hasCustomRules?: boolean,
|
||||||
): string {
|
): string {
|
||||||
const state = session.currentState;
|
const state = session.currentState;
|
||||||
const summary = session.storySummary || "The story just began.";
|
const summary = session.storySummary || "The story just began.";
|
||||||
@@ -275,8 +276,9 @@ export function buildDynamicContext(
|
|||||||
: "No significant events yet.";
|
: "No significant events yet.";
|
||||||
|
|
||||||
// Add rule reminders after 10+ messages to prevent drift
|
// Add rule reminders after 10+ messages to prevent drift
|
||||||
|
// Skip if story has custom rules - they take priority
|
||||||
const ruleReminder =
|
const ruleReminder =
|
||||||
messageCount && messageCount >= 10
|
messageCount && messageCount >= 10 && !hasCustomRules
|
||||||
? `
|
? `
|
||||||
|
|
||||||
=== REMINDER ===
|
=== REMINDER ===
|
||||||
@@ -326,8 +328,9 @@ export async function generateStoryResponse(
|
|||||||
const worldContext = buildWorldContext(story);
|
const worldContext = buildWorldContext(story);
|
||||||
|
|
||||||
// 3. Dynamic context (state + summary + rule reminders after 10+ messages)
|
// 3. Dynamic context (state + summary + rule reminders after 10+ messages)
|
||||||
|
const hasCustomRules = Boolean(story.narrativeRules?.trim());
|
||||||
const dynamicContext = session
|
const dynamicContext = session
|
||||||
? buildDynamicContext(session, chatHistory.length)
|
? buildDynamicContext(session, chatHistory.length, hasCustomRules)
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
// 4. Last N messages (not the full history!)
|
// 4. Last N messages (not the full history!)
|
||||||
@@ -363,8 +366,9 @@ export async function generateStoryResponseStream(
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const styleRules = buildStyleRules(story, player);
|
const styleRules = buildStyleRules(story, player);
|
||||||
const worldContext = buildWorldContext(story);
|
const worldContext = buildWorldContext(story);
|
||||||
|
const hasCustomRules = Boolean(story.narrativeRules?.trim());
|
||||||
const dynamicContext = session
|
const dynamicContext = session
|
||||||
? buildDynamicContext(session, chatHistory.length)
|
? buildDynamicContext(session, chatHistory.length, hasCustomRules)
|
||||||
: "";
|
: "";
|
||||||
const recentMessages = chatHistory.slice(-RECENT_MESSAGES_COUNT);
|
const recentMessages = chatHistory.slice(-RECENT_MESSAGES_COUNT);
|
||||||
const systemPrompt = styleRules + "\n" + worldContext + "\n" + dynamicContext;
|
const systemPrompt = styleRules + "\n" + worldContext + "\n" + dynamicContext;
|
||||||
|
|||||||
Reference in New Issue
Block a user