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

View File

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

View File

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

View File

@ -323,7 +323,7 @@ namespace Prompt {
newMessages: Iterable<ChatMessage> = [],
excludedMessageIds: Iterable<string> = [],
): LLM.ChatCompletionRequest | null {
const { currentStory, model, enableThinking } = state;
const { currentStory, model, enableThinking, currentWorld } = state;
if (!currentStory || !model) {
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
let storyTokenBudget = 0;
@ -365,7 +392,7 @@ namespace Prompt {
return {
model: model.id,
messages,
tools: state.currentWorld?.chatOnly ? undefined : Tools.getTools(),
tools: Tools.getTools(),
banned_tokens: state.bannedTokens,
enable_thinking: enableThinking,
max_tokens: model.max_length ? model.max_length : 2048,