Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- src/openai_patch.ts +1 -0
- 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 ||
|
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 (
|
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 +=
|
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:
|
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 |
}
|