1
0
Fork 0

Add usernames to chat messages

This commit is contained in:
Pabloader 2026-04-07 19:41:22 +00:00
parent 0f326ac6ea
commit f685118da0
4 changed files with 61 additions and 26 deletions

View File

@ -167,6 +167,8 @@ export const ChatPanel = () => {
} }
try { try {
const charName = currentWorld.title ?? 'Assistant';
const prefix = `${charName}: `;
let accumulatedContent = ''; let accumulatedContent = '';
let accumulatedReasoning = ''; let accumulatedReasoning = '';
let tool_calls: LLM.ToolCall[] | undefined; let tool_calls: LLM.ToolCall[] | undefined;
@ -184,6 +186,9 @@ export const ChatPanel = () => {
const content = delta?.content; const content = delta?.content;
if (content) { if (content) {
accumulatedContent += content; accumulatedContent += content;
if (currentWorld?.chatOnly && accumulatedContent.startsWith(prefix)) {
accumulatedContent = accumulatedContent.slice(prefix.length);
}
} }
const reasoningContent = delta?.reasoning_content; const reasoningContent = delta?.reasoning_content;
if (reasoningContent) { if (reasoningContent) {
@ -496,6 +501,7 @@ export const ChatPanel = () => {
)} )}
{currentStory && ( {currentStory && (
<div class={styles.inputContainer}> <div class={styles.inputContainer}>
{!currentWorld?.chatOnly && (
<div class={styles.optionsRow}> <div class={styles.optionsRow}>
<label class={styles.toggleContainer}> <label class={styles.toggleContainer}>
<input <input
@ -520,6 +526,7 @@ export const ChatPanel = () => {
</button> </button>
</div> </div>
</div> </div>
)}
<ContentEditable <ContentEditable
autoLines autoLines
class={styles.input} class={styles.input}

View File

@ -330,7 +330,7 @@ function reducer(state: IState, action: Action): IState {
...state, ...state,
currentWorldId: action.worldId, currentWorldId: action.worldId,
currentStoryId: action.id, currentStoryId: action.id,
currentTab: world?.chatOnly ? 'chat' : 'story', currentTab: 'menu',
}; };
} }
case 'DUPLICATE_STORY': { case 'DUPLICATE_STORY': {

View File

@ -62,6 +62,7 @@ namespace LLM {
frequency_penalty?: number; frequency_penalty?: number;
presence_penalty?: number; presence_penalty?: number;
enable_thinking?: boolean; enable_thinking?: boolean;
add_generation_prompt?: boolean;
} }
export interface ChatCompletionChoice { export interface ChatCompletionChoice {

View File

@ -323,7 +323,7 @@ namespace Prompt {
newMessages: Iterable<ChatMessage> = [], newMessages: Iterable<ChatMessage> = [],
excludedMessageIds: Iterable<string> = [], excludedMessageIds: Iterable<string> = [],
): LLM.ChatCompletionRequest | null { ): LLM.ChatCompletionRequest | null {
const { currentStory, model, enableThinking } = state; const { currentStory, model, enableThinking, currentWorld } = state;
if (!currentStory || !model) { if (!currentStory || !model) {
return null; return null;
@ -345,6 +345,33 @@ namespace Prompt {
} }
} }
// Chat-only world: format messages with name prefixes
if (currentWorld?.chatOnly) {
const charName = currentWorld.title ?? 'Assistant';
const formattedMessages: ChatMessage[] = messages.map(msg => {
const prefix = msg.role === 'user' ? 'User' : charName;
return {
...msg,
content: `${prefix}: ${msg.content}`,
};
});
// Prepend system message
formattedMessages.unshift({
id: crypto.randomUUID(),
role: 'system',
content: formatSystemPrompt(state, 0),
});
return {
model: model.id,
messages: formattedMessages,
enable_thinking: false,
max_tokens: model.max_length ? model.max_length : 2048,
add_generation_prompt: true,
banned_tokens: state.bannedTokens,
};
}
// Estimate token budget for story text // Estimate token budget for story text
let storyTokenBudget = 0; let storyTokenBudget = 0;
@ -365,7 +392,7 @@ namespace Prompt {
return { return {
model: model.id, model: model.id,
messages, messages,
tools: state.currentWorld?.chatOnly ? undefined : Tools.getTools(), tools: Tools.getTools(),
banned_tokens: state.bannedTokens, banned_tokens: state.bannedTokens,
enable_thinking: enableThinking, enable_thinking: enableThinking,
max_tokens: model.max_length ? model.max_length : 2048, max_tokens: model.max_length ? model.max_length : 2048,