Wauplin HF Staff commited on
Commit
d28f5fa
·
verified ·
1 Parent(s): 0d57d62

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. src/openai_patch.ts +1 -0
  2. src/routes/responses.ts +5 -4
src/openai_patch.ts CHANGED
@@ -46,4 +46,5 @@ export type PatchedResponseContentPart = ResponseOutputText | ResponseOutputRefu
46
 
47
  export type PatchedDeltaWithReasoning = ChatCompletionChunk.Choice.Delta & {
48
  reasoning?: string;
 
49
  };
 
46
 
47
  export type PatchedDeltaWithReasoning = ChatCompletionChunk.Choice.Delta & {
48
  reasoning?: string;
49
+ reasoning_content?: string;
50
  };
src/routes/responses.ts CHANGED
@@ -519,12 +519,13 @@ async function* handleOneTurnStream(
519
  }
520
 
521
  const delta = chunk.choices[0].delta as PatchedDeltaWithReasoning;
 
522
 
523
- if (delta.content || delta.reasoning) {
524
  let currentOutputItem = responseObject.output.at(-1);
525
 
526
  // If start or end of reasoning, skip token and update the current text mode
527
- if (delta.reasoning) {
528
  if (currentTextMode === "text") {
529
  for await (const event of closeLastOutputItem(responseObject, payload, mcpToolsMapping)) {
530
  yield event;
@@ -642,13 +643,13 @@ async function* handleOneTurnStream(
642
 
643
  // Add text delta
644
  const contentPart = currentReasoningItem.content.at(-1) as ReasoningTextContent;
645
- contentPart.text += delta.reasoning;
646
  yield {
647
  type: "response.reasoning_text.delta",
648
  item_id: currentReasoningItem.id,
649
  output_index: responseObject.output.length - 1,
650
  content_index: currentReasoningItem.content.length - 1,
651
- delta: delta.reasoning as string,
652
  sequence_number: SEQUENCE_NUMBER_PLACEHOLDER,
653
  };
654
  }
 
519
  }
520
 
521
  const delta = chunk.choices[0].delta as PatchedDeltaWithReasoning;
522
+ const reasoningText = delta.reasoning ?? delta.reasoning_content;
523
 
524
+ if (delta.content || reasoningText) {
525
  let currentOutputItem = responseObject.output.at(-1);
526
 
527
  // If start or end of reasoning, skip token and update the current text mode
528
+ if (reasoningText) {
529
  if (currentTextMode === "text") {
530
  for await (const event of closeLastOutputItem(responseObject, payload, mcpToolsMapping)) {
531
  yield event;
 
643
 
644
  // Add text delta
645
  const contentPart = currentReasoningItem.content.at(-1) as ReasoningTextContent;
646
+ contentPart.text += reasoningText;
647
  yield {
648
  type: "response.reasoning_text.delta",
649
  item_id: currentReasoningItem.id,
650
  output_index: responseObject.output.length - 1,
651
  content_index: currentReasoningItem.content.length - 1,
652
+ delta: reasoningText as string,
653
  sequence_number: SEQUENCE_NUMBER_PLACEHOLDER,
654
  };
655
  }