Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/subcommands/chat/react/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const ChatComponent = React.memo(
const [userInputState, setUserInputState] = useState<ChatUserInputState>(emptyChatInputState);
const [isPredicting, setIsPredicting] = useState(false);
const [showPredictionSpinner, setShowPredictionSpinner] = useState(false);
const [systemAsUser, setSystemAsUser] = useState(false);
const [modelLoadingProgress, setModelLoadingProgress] = useState<number | null>(null);
const [statusMessage, setStatusMessage] = useState<string | null>(null);
const [flickerCount, setFlickerCount] = useState(0);
Expand Down Expand Up @@ -160,6 +161,8 @@ export const ChatComponent = React.memo(
setModelLoadingProgress,
modelLoadingAbortControllerRef,
lastPredictionStatsRef,
systemAsUser,
setSystemAsUser,
});
handler.setCommands(commands);
return handler;
Expand All @@ -174,6 +177,7 @@ export const ChatComponent = React.memo(
logInChat,
logErrorInChat,
shouldFetchModelCatalog,
systemAsUser,
]);

const suggestions = useMemo<Suggestion[]>(() => {
Expand Down
35 changes: 33 additions & 2 deletions src/subcommands/chat/react/slashCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface CreateSlashCommandsOpts {
setModelLoadingProgress: Dispatch<SetStateAction<number | null>>;
modelLoadingAbortControllerRef: RefObject<AbortController | null>;
lastPredictionStatsRef: RefObject<LLMPredictionStats | null>;
systemAsUser: boolean;
setSystemAsUser: Dispatch<SetStateAction<boolean>>;
}

export function createSlashCommands({
Expand All @@ -50,6 +52,8 @@ export function createSlashCommands({
setModelLoadingProgress,
modelLoadingAbortControllerRef,
lastPredictionStatsRef,
systemAsUser,
setSystemAsUser,
}: CreateSlashCommandsOpts): SlashCommand[] {
return [
{
Expand Down Expand Up @@ -150,9 +154,12 @@ export function createSlashCommands({
cursorInSegmentOffset: 0,
});
console.clear();
const systemPrompt = chatRef.current.getSystemPrompt();
const systemPrompt = systemAsUser
? chatRef.current.at(0).getText()
: chatRef.current.getSystemPrompt();
const role = systemAsUser ? "user" : "system";
chatRef.current = Chat.empty();
chatRef.current.append("system", systemPrompt);
chatRef.current.append(role, systemPrompt);
lastPredictionStatsRef.current = null;
},
},
Expand All @@ -170,6 +177,30 @@ export function createSlashCommands({
logInChat("System prompt updated to: " + prompt);
},
},
{
name: "system-as-user",
description: "Toggle sending system messages as user messages",
handler: async () => {
setMessages([]);
setUserInputState({
segments: [{ type: "text", content: "" }],
cursorOnSegmentIndex: 0,
cursorInSegmentOffset: 0,
});
console.clear();
setSystemAsUser(!systemAsUser);

const systemPrompt = systemAsUser
? chatRef.current.at(0).getText()
: chatRef.current.getSystemPrompt();
const role = !systemAsUser ? "user" : "system";

chatRef.current = Chat.empty();
chatRef.current.append(role, systemPrompt);

logInChat(`System messages will now be sent as ${role} messages.`);
},
},
{
name: "stats",
description: "Show stats of the previous generation",
Expand Down