Skip to content
Merged
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
10 changes: 8 additions & 2 deletions frontend/src/hooks/useChatSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ export function useChatSession(
content: string,
images?: File[],
documentText?: string,
documentMetadata?: { filename: string; fullContent: string }
documentMetadata?: { filename: string; fullContent: string },
systemPrompt?: string
) => {
if (phase !== "idle") {
return;
Expand Down Expand Up @@ -209,7 +210,12 @@ export function useChatSession(
processingRef.current = true;
setPhase("streaming");

const newMessages = [...chat.messages, userMessage];
// Add system message first if provided
const newMessages = [...chat.messages];
if (systemPrompt && systemPrompt.trim()) {
newMessages.push({ role: "system", content: systemPrompt.trim() } as ChatMessage);
}
newMessages.push(userMessage);
Comment thread
AnthonyRonning marked this conversation as resolved.

// Update optimistic state immediately
setOptimisticChat({
Expand Down
14 changes: 4 additions & 10 deletions frontend/src/routes/_auth.chat.$chatId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,8 @@ function ChatComponent() {
setSystemPrompt(null);
setUserImages([]);

// Combine prompts
const finalPrompt = sysPrompt ? `[System: ${sysPrompt}]\n\n${prompt}` : prompt;

// Send message
appendUserMessage(finalPrompt, images).catch((error) => {
// Send message with system prompt as separate parameter
appendUserMessage(prompt, images, undefined, undefined, sysPrompt || undefined).catch((error) => {
// Only reset if it wasn't an abort
if (!(error instanceof Error) || error.message !== "Stream aborted") {
console.error("[ChatComponent] Failed to append message:", error);
Expand Down Expand Up @@ -361,11 +358,8 @@ function ChatComponent() {
documentText?: string,
documentMetadata?: { filename: string; fullContent: string }
) => {
// Handle system prompt if provided
const messageContent = systemPrompt ? `[System: ${systemPrompt}]\n\n${input}` : input;

// Use the appendUserMessage from the hook
await appendUserMessage(messageContent, images, documentText, documentMetadata);
// Use the appendUserMessage from the hook with system prompt as separate parameter
await appendUserMessage(input, images, documentText, documentMetadata, systemPrompt);

// Scroll to bottom after sending
requestAnimationFrame(() => {
Expand Down
Loading