Skip to content

Commit ba3ccc3

Browse files
committed
Fix: Strip trailing empty assistant message
1 parent 411545f commit ba3ccc3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/streaming.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ export const buildBody=()=>{
2727
});
2828
});
2929

30+
// Strip trailing empty assistant message (prevents 400 on models without prefill support)
31+
// We keep the UI bubble in main.js, but the API never sees the empty placeholder.
32+
if (msgs.length > 0) {
33+
const last = msgs[msgs.length - 1];
34+
if (last.role === 'assistant' && last.content.length === 0 && (!last.images || last.images.length === 0)) {
35+
msgs.pop();
36+
}
37+
}
38+
3039
const b=payloadWithSampling({model:SUNE.model.replace(/^(or:|oai:|g:|cla:|cf:)/,''),messages:msgs,stream:true});
3140
if(SUNE.json_output){let s;try{s=JSON.parse(SUNE.json_schema||'null')}catch{s=null}if(s&&typeof s==='object'&&Object.keys(s).length>0){b.response_format={type:'json_schema',json_schema:s}}else{b.response_format={type:'json_object'}}}
3241
b.reasoning={...(SUNE.reasoning_effort&&SUNE.reasoning_effort!=='default'?{effort:SUNE.reasoning_effort}:{}),exclude:!SUNE.include_thoughts};

0 commit comments

Comments
 (0)