File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments