fix(ai): openai-completions - throw error on missing finish-reason
- require \ before treating \ streams as successful - add regression coverage for truncated streams without \ - closes #4345
This commit is contained in:
@@ -441,6 +441,38 @@ describe("openai-completions tool_choice", () => {
|
||||
expect(response.content).toEqual([{ type: "text", text: "OK" }]);
|
||||
});
|
||||
|
||||
it("errors when a stream ends after only null finish_reason chunks", async () => {
|
||||
mockState.chunks = [
|
||||
{
|
||||
id: "chatcmpl-truncated",
|
||||
choices: [{ delta: { content: "partial answer" }, finish_reason: null }],
|
||||
},
|
||||
{
|
||||
id: "chatcmpl-truncated",
|
||||
choices: [{ delta: { content: "partial answer" }, finish_reason: null }],
|
||||
},
|
||||
];
|
||||
|
||||
const { compat: _compat, ...baseModel } = getModel("openai", "gpt-4o-mini")!;
|
||||
const model = { ...baseModel, api: "openai-completions" } as const;
|
||||
const response = await streamSimple(
|
||||
model,
|
||||
{
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "Reply with a longer sentence",
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{ apiKey: "test" },
|
||||
).result();
|
||||
|
||||
expect(response.stopReason).toBe("error");
|
||||
expect(response.errorMessage).toBe("Stream ended without finish_reason");
|
||||
});
|
||||
|
||||
it("coalesces tool call deltas by stable index when provider mutates ids mid-stream", async () => {
|
||||
mockState.chunks = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user