File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -855,8 +855,8 @@ describe("MimoHandler", () => {
855855
856856 const toolChunks = chunks . filter ( ( c ) => c . type === "tool_call_partial" )
857857 expect ( toolChunks . length ) . toBeGreaterThan ( 0 )
858- expect ( toolChunks [ 0 ] . id ) . toBeDefined ( )
859- expect ( typeof toolChunks [ 0 ] . id ) . toBe ( "string" )
858+ expect ( toolChunks [ 0 ] . id ) . toBe ( sanitizeOpenAiCallId ( "call_with-special.chars@123" ) )
859+ expect ( toolChunks [ 0 ] . id ) . not . toMatch ( / [ ^ a - z A - Z 0 - 9 _ - ] / )
860860 } )
861861
862862 it ( "should convert system prompt to system message for MiMo" , async ( ) => {
Original file line number Diff line number Diff line change @@ -110,6 +110,15 @@ export class MimoHandler extends OpenAiHandler {
110110 for await ( const chunk of stream ) {
111111 const delta = chunk . choices ?. [ 0 ] ?. delta ?? { }
112112 const finishReason = chunk . choices ?. [ 0 ] ?. finish_reason
113+ const sanitizedDelta = delta . tool_calls
114+ ? {
115+ ...delta ,
116+ tool_calls : delta . tool_calls . map ( ( toolCall ) => ( {
117+ ...toolCall ,
118+ id : toolCall . id ? sanitizeOpenAiCallId ( toolCall . id ) : toolCall . id ,
119+ } ) ) ,
120+ }
121+ : delta
113122
114123 if ( delta . content ) {
115124 yield {
@@ -125,7 +134,7 @@ export class MimoHandler extends OpenAiHandler {
125134 }
126135 }
127136
128- yield * this . processToolCalls ( delta , finishReason , activeToolCallIds )
137+ yield * this . processToolCalls ( sanitizedDelta , finishReason , activeToolCallIds )
129138
130139 if ( chunk . usage ) {
131140 lastUsage = chunk . usage
You can’t perform that action at this time.
0 commit comments