incognitolm commited on
Commit
da25d85
·
1 Parent(s): 8d92415

Update chatStream.js

Browse files
Files changed (1) hide show
  1. server/chatStream.js +27 -5
server/chatStream.js CHANGED
@@ -364,7 +364,7 @@ export async function streamChat({
364
  {
365
  role: "assistant",
366
  content: assistantText || "",
367
- tool_calls: toolCalls,
368
  },
369
  ...toolResults
370
  );
@@ -376,10 +376,32 @@ export async function streamChat({
376
  stream: true,
377
  };
378
 
379
- const followUp =
380
- await websocketChatStream(followUpBody, headers, onToken, abortSignal);
381
-
382
- assistantText += followUp.assistantText;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  }
384
 
385
  const sessionName = extractSessionName(assistantText);
 
364
  {
365
  role: "assistant",
366
  content: assistantText || "",
367
+ tool_calls: toolCalls.length > 0 ? toolCalls : undefined,
368
  },
369
  ...toolResults
370
  );
 
376
  stream: true,
377
  };
378
 
379
+ let followUpAssistantText = "";
380
+ for (let attempt = 0; attempt < 2; attempt++) {
381
+ const followUp = await websocketChatStream(followUpBody, headers, onToken, abortSignal);
382
+ followUpAssistantText += followUp.assistantText;
383
+
384
+ // If the model returned new tool calls, process them and update the body
385
+ if (followUp.toolCalls.length > 0) {
386
+ const toolResults = await processToolCalls(
387
+ null,
388
+ followUp.toolCalls,
389
+ tools,
390
+ accessToken,
391
+ clientId,
392
+ abortSignal,
393
+ onToolCall,
394
+ onNewAsset
395
+ );
396
+ followUpMessages.push(...toolResults);
397
+
398
+ // Update body for another pass
399
+ followUpBody.messages = followUpMessages;
400
+ } else {
401
+ break; // no new tool calls, we’re done
402
+ }
403
+ }
404
+ assistantText += followUpAssistantText;
405
  }
406
 
407
  const sessionName = extractSessionName(assistantText);