mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
fix: use replaceAll for think tags to handle multiple occurrences
This commit is contained in:
@@ -377,7 +377,7 @@ export function createResponsesApiTransformStream(logger = null) {
|
||||
|
||||
if (content.includes("<think>")) {
|
||||
state.inThinking = true;
|
||||
content = content.replace("<think>", "");
|
||||
content = content.replaceAll("<think>", "");
|
||||
startReasoning(controller, idx);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ export function openaiToOpenAIResponsesResponse(chunk, state) {
|
||||
|
||||
if (content.includes("<think>")) {
|
||||
state.inThinking = true;
|
||||
content = content.replace("<think>", "");
|
||||
content = content.replaceAll("<think>", "");
|
||||
startReasoning(state, emit, idx);
|
||||
}
|
||||
|
||||
|
||||
@@ -403,3 +403,20 @@ test("Responses→Chat streaming: reasoning delta emits reasoning_content in Cha
|
||||
assert.ok(result, "should return a chunk");
|
||||
assert.equal(result.choices[0].delta.reasoning_content, "thinking step...");
|
||||
});
|
||||
|
||||
test("Chat→Responses streaming: multiple <think> tags in one chunk handled", () => {
|
||||
const state = initState(FORMATS.OPENAI_RESPONSES);
|
||||
|
||||
// Chunk with multiple think tags
|
||||
const chunk = {
|
||||
choices: [{ index: 0, delta: { content: "<think>first</think>middle<think>second</think>end" }, finish_reason: null }],
|
||||
id: "c1",
|
||||
};
|
||||
const events = openaiToOpenAIResponsesResponse(chunk, state);
|
||||
// Should not have literal <think> in any text delta
|
||||
const textDeltas = events
|
||||
.filter((e) => e.event === "response.output_text.delta")
|
||||
.map((e) => e.data.delta);
|
||||
const combined = textDeltas.join("");
|
||||
assert.ok(!combined.includes("<think>"), `text should not contain <think> tag, got: ${combined}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user