Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,75 @@ describe("BaseOpenAiCompatibleProvider", () => {
])
})

it("should handle reasoning tags (<thought>) from stream", async () => {
Comment thread
sagidM marked this conversation as resolved.
mockCreate.mockImplementationOnce(() => {
return {
[Symbol.asyncIterator]: () => ({
next: vi
.fn()
.mockResolvedValueOnce({
done: false,
value: { choices: [{ delta: { content: "<thought>Deep thought" } }] },
})
.mockResolvedValueOnce({
done: false,
value: { choices: [{ delta: { content: " here</thought>" } }] },
})
.mockResolvedValueOnce({
done: false,
value: { choices: [{ delta: { content: "Result: 42" } }] },
})
.mockResolvedValueOnce({ done: true }),
}),
}
})
const stream = handler.createMessage("system prompt", [])
const chunks = []
for await (const chunk of stream) {
chunks.push(chunk)
}
expect(chunks).toEqual([
{ type: "reasoning", text: "Deep thought" },
{ type: "reasoning", text: " here" },
{ type: "text", text: "Result: 42" },
])
})

it("should not close <think> tag with </thought> tag", async () => {
mockCreate.mockImplementationOnce(() => {
return {
[Symbol.asyncIterator]: () => ({
next: vi
.fn()
.mockResolvedValueOnce({
done: false,
value: { choices: [{ delta: { content: "<think>Thinking" } }] },
})
.mockResolvedValueOnce({
done: false,
value: { choices: [{ delta: { content: " but closing with wrong tag</thought>" } }] },
})
.mockResolvedValueOnce({
done: false,
value: { choices: [{ delta: { content: " still thinking" } }] },
})
.mockResolvedValueOnce({ done: true }),
}),
}
})
const stream = handler.createMessage("system prompt", [])
const chunks = []
for await (const chunk of stream) {
chunks.push(chunk)
}
// The </thought> tag should be treated as text since it doesn't match the active <think> tag
expect(chunks).toEqual([
{ type: "reasoning", text: "Thinking" },
{ type: "reasoning", text: " but closing with wrong tag</thought>" },
{ type: "reasoning", text: " still thinking" },
])
})

it("should handle complete <think> tag in a single chunk", async () => {
mockCreate.mockImplementationOnce(() => {
return {
Expand Down
Loading
Loading