File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -224,7 +224,7 @@ export class ClaudeApi implements LLMApi {
224224 let chunkJson :
225225 | undefined
226226 | {
227- type : "content_block_delta" | "content_block_stop" ;
227+ type : "content_block_delta" | "content_block_stop" | "message_delta" | "message_stop" ;
228228 content_block ?: {
229229 type : "tool_use" ;
230230 id : string ;
@@ -234,11 +234,20 @@ export class ClaudeApi implements LLMApi {
234234 type : "text_delta" | "input_json_delta" ;
235235 text ?: string ;
236236 partial_json ?: string ;
237+ stop_reason ?: string ;
237238 } ;
238239 index : number ;
239240 } ;
240241 chunkJson = JSON . parse ( text ) ;
241242
243+ // Handle refusal stop reason in message_delta
244+ if ( chunkJson ?. delta ?. stop_reason === "refusal" ) {
245+ // Return a message to display to the user
246+ const refusalMessage = "\n\n[Assistant refused to respond. Please modify your request and try again.]" ;
247+ options . onError ?.( new Error ( "Content policy violation: " + refusalMessage ) ) ;
248+ return refusalMessage ;
249+ }
250+
242251 if ( chunkJson ?. content_block ?. type == "tool_use" ) {
243252 index += 1 ;
244253 const id = chunkJson ?. content_block . id ;
Original file line number Diff line number Diff line change @@ -571,6 +571,8 @@ const anthropicModels = [
571571 "claude-3-5-sonnet-latest" ,
572572 "claude-3-7-sonnet-20250219" ,
573573 "claude-3-7-sonnet-latest" ,
574+ "claude-sonnet-4-20250514" ,
575+ "claude-opus-4-20250514" ,
574576] ;
575577
576578const baiduModels = [
You can’t perform that action at this time.
0 commit comments