Skip to content

Commit 9a24d3f

Browse files
committed
extra context first, then user input in the end
1 parent 2d2b8de commit 9a24d3f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

tools/server/public/index.html.gz

1 Byte
Binary file not shown.

tools/server/webui/src/utils/misc.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,9 @@ export function normalizeMsgsForAPI(messages: Readonly<Message[]>) {
6969
} as APIMessage;
7070
}
7171

72-
const contentArr: APIMessageContentPart[] = [
73-
{
74-
type: 'text',
75-
text: msg.content,
76-
},
77-
];
72+
// extra content first, then user text message in the end
73+
// this allow re-using the same cache prefix for long context
74+
const contentArr: APIMessageContentPart[] = [];
7875

7976
for (const extra of msg.extra ?? []) {
8077
if (extra.type === 'context') {
@@ -97,6 +94,12 @@ export function normalizeMsgsForAPI(messages: Readonly<Message[]>) {
9794
}
9895
}
9996

97+
// add user message to the end
98+
contentArr.push({
99+
type: 'text',
100+
text: msg.content,
101+
});
102+
100103
return {
101104
role: msg.role,
102105
content: contentArr,

0 commit comments

Comments
 (0)