Add usernames to chat messages
This commit is contained in:
parent
0f326ac6ea
commit
f685118da0
|
|
@ -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,30 +501,32 @@ export const ChatPanel = () => {
|
||||||
)}
|
)}
|
||||||
{currentStory && (
|
{currentStory && (
|
||||||
<div class={styles.inputContainer}>
|
<div class={styles.inputContainer}>
|
||||||
<div class={styles.optionsRow}>
|
{!currentWorld?.chatOnly && (
|
||||||
<label class={styles.toggleContainer}>
|
<div class={styles.optionsRow}>
|
||||||
<input
|
<label class={styles.toggleContainer}>
|
||||||
type="checkbox"
|
<input
|
||||||
checked={enableThinking}
|
type="checkbox"
|
||||||
onChange={(e) => dispatch({
|
checked={enableThinking}
|
||||||
type: 'SET_ENABLE_THINKING',
|
onChange={(e) => dispatch({
|
||||||
enable: (e.target as HTMLInputElement).checked,
|
type: 'SET_ENABLE_THINKING',
|
||||||
})}
|
enable: (e.target as HTMLInputElement).checked,
|
||||||
disabled={isDisabled}
|
})}
|
||||||
/>
|
disabled={isDisabled}
|
||||||
<span>Enable thinking</span>
|
/>
|
||||||
</label>
|
<span>Enable thinking</span>
|
||||||
<div class={styles.tokenCounter}>
|
</label>
|
||||||
{tokenCount && <span>{tokenCount.taken} / {tokenCount.total} tokens</span>}
|
<div class={styles.tokenCounter}>
|
||||||
<button
|
{tokenCount && <span>{tokenCount.taken} / {tokenCount.total} tokens</span>}
|
||||||
class={styles.summarizeButton}
|
<button
|
||||||
onClick={summarizeAll}
|
class={styles.summarizeButton}
|
||||||
disabled={isSummarizing || !currentStory || !connection || !model}
|
onClick={summarizeAll}
|
||||||
title={isSummarizing ? 'Summarizing...' : 'Summarize'}>
|
disabled={isSummarizing || !currentStory || !connection || !model}
|
||||||
<Sparkles size={14} />
|
title={isSummarizing ? 'Summarizing...' : 'Summarize'}>
|
||||||
</button>
|
<Sparkles size={14} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
<ContentEditable
|
<ContentEditable
|
||||||
autoLines
|
autoLines
|
||||||
class={styles.input}
|
class={styles.input}
|
||||||
|
|
|
||||||
|
|
@ -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': {
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue