Skip to content

Commit e0187df

Browse files
committed
fix: Don't send empty system message in the messages array
1 parent b5d2f1e commit e0187df

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

tools/server/public/index.html.gz

32 Bytes
Binary file not shown.

tools/server/webui/src/lib/services/chat.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,28 @@ export class ChatService {
8383
this.abortController = new AbortController();
8484

8585
// Convert database messages with attachments to API format if needed
86-
const normalizedMessages: ApiChatMessageData[] = messages.map((msg) => {
87-
// Check if this is a DatabaseMessage by checking for DatabaseMessage-specific fields
88-
if ('id' in msg && 'convId' in msg && 'timestamp' in msg) {
89-
// This is a DatabaseMessage, convert it
90-
const dbMsg = msg as DatabaseMessage & { extra?: DatabaseMessageExtra[] };
91-
return ChatService.convertMessageToChatServiceData(dbMsg);
92-
} else {
93-
// This is already an ApiChatMessageData object
94-
return msg as ApiChatMessageData;
95-
}
96-
});
86+
const normalizedMessages: ApiChatMessageData[] = messages
87+
.map((msg) => {
88+
// Check if this is a DatabaseMessage by checking for DatabaseMessage-specific fields
89+
if ('id' in msg && 'convId' in msg && 'timestamp' in msg) {
90+
// This is a DatabaseMessage, convert it
91+
const dbMsg = msg as DatabaseMessage & { extra?: DatabaseMessageExtra[] };
92+
return ChatService.convertMessageToChatServiceData(dbMsg);
93+
} else {
94+
// This is already an ApiChatMessageData object
95+
return msg as ApiChatMessageData;
96+
}
97+
})
98+
.filter((msg) => {
99+
// Filter out empty system messages
100+
if (msg.role === 'system') {
101+
const content = typeof msg.content === 'string' ? msg.content : '';
102+
103+
return content.trim().length > 0;
104+
}
105+
106+
return true;
107+
});
97108

98109
// Build base request body with system message injection
99110
const processedMessages = this.injectSystemMessage(normalizedMessages);

0 commit comments

Comments
 (0)