Skip to content

Commit 63504d2

Browse files
giulio-leoneCopilot
andcommitted
test(openai-compatible): add Azure SSE regression test for empty choices handling
Adds regression test with Azure SSE fixture covering: - Empty choices array with prompt_filter_results - Extra fields (obfuscation) in delta chunks - Post-completion content_filter_results chunks - Verifies existing code already handles Azure format correctly Ref #12056 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c123363 commit 63504d2

3 files changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{"choices":[],"created":0,"id":"","model":"","object":"","prompt_filter_results":[{"prompt_index":0,"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"jailbreak":{"filtered":false,"detected":false},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}}}]}
2+
{"choices":[{"content_filter_results":{},"delta":{"content":"","refusal":null,"role":"assistant"},"finish_reason":null,"index":0,"logprobs":null}],"created":1762317021,"id":"chatcmpl-test","model":"gpt-4","obfuscation":"D3WbtIxo1Q2j1Q","object":"chat.completion.chunk","system_fingerprint":null,"usage":null}
3+
{"choices":[{"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"delta":{"content":"Hello"},"finish_reason":null,"index":0,"logprobs":null}],"created":1762317021,"id":"chatcmpl-test","model":"gpt-4","obfuscation":"NNpA6Dj2U","object":"chat.completion.chunk","system_fingerprint":null,"usage":null}
4+
{"choices":[{"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"delta":{"content":" World"},"finish_reason":null,"index":0,"logprobs":null}],"created":1762317021,"id":"chatcmpl-test","model":"gpt-4","obfuscation":"etvV32yk5dbxb","object":"chat.completion.chunk","system_fingerprint":null,"usage":null}
5+
{"choices":[{"content_filter_results":{},"delta":{},"finish_reason":"stop","index":0,"logprobs":null}],"created":1762317021,"id":"chatcmpl-test","model":"gpt-4","obfuscation":"Zarov0xJhP","object":"chat.completion.chunk","system_fingerprint":null,"usage":null}
6+
{"choices":[{"content_filter_offsets":{"check_offset":0,"start_offset":0,"end_offset":11},"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"finish_reason":null,"index":0}],"created":1762317021,"id":"chatcmpl-test","model":"gpt-4","object":"chat.completion.chunk","system_fingerprint":null}
7+
{"choices":[],"created":1762317021,"id":"chatcmpl-test","model":"gpt-4","obfuscation":"DjqQ9RbEQMJ3PX","object":"chat.completion.chunk","system_fingerprint":null,"usage":{"completion_tokens":5,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens":15,"prompt_tokens_details":{"audio_tokens":0,"cached_tokens":0},"total_tokens":20}}

packages/openai-compatible/src/chat/__snapshots__/openai-compatible-chat-language-model.test.ts.snap

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,78 @@ Finally, structure it as: <function_call>{"action": "weather", "action_input": {
298298
}
299299
`;
300300

301+
exports[`doStream > Azure text (fixture) > should stream text content with Azure SSE format 1`] = `
302+
[
303+
{
304+
"type": "stream-start",
305+
"warnings": [],
306+
},
307+
{
308+
"id": "",
309+
"modelId": "",
310+
"timestamp": 1970-01-01T00:00:00.000Z,
311+
"type": "response-metadata",
312+
},
313+
{
314+
"id": "txt-0",
315+
"type": "text-start",
316+
},
317+
{
318+
"delta": "Hello",
319+
"id": "txt-0",
320+
"type": "text-delta",
321+
},
322+
{
323+
"delta": " World",
324+
"id": "txt-0",
325+
"type": "text-delta",
326+
},
327+
{
328+
"id": "txt-0",
329+
"type": "text-end",
330+
},
331+
{
332+
"finishReason": {
333+
"raw": "stop",
334+
"unified": "stop",
335+
},
336+
"providerMetadata": {
337+
"test-provider": {
338+
"acceptedPredictionTokens": 0,
339+
"rejectedPredictionTokens": 0,
340+
},
341+
},
342+
"type": "finish",
343+
"usage": {
344+
"inputTokens": {
345+
"cacheRead": 0,
346+
"cacheWrite": undefined,
347+
"noCache": 15,
348+
"total": 15,
349+
},
350+
"outputTokens": {
351+
"reasoning": 0,
352+
"text": 5,
353+
"total": 5,
354+
},
355+
"raw": {
356+
"completion_tokens": 5,
357+
"completion_tokens_details": {
358+
"accepted_prediction_tokens": 0,
359+
"reasoning_tokens": 0,
360+
"rejected_prediction_tokens": 0,
361+
},
362+
"prompt_tokens": 15,
363+
"prompt_tokens_details": {
364+
"cached_tokens": 0,
365+
},
366+
"total_tokens": 20,
367+
},
368+
},
369+
},
370+
]
371+
`;
372+
301373
exports[`doStream > text (fixture) > should stream text content 1`] = `
302374
[
303375
{

packages/openai-compatible/src/chat/openai-compatible-chat-language-model.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,21 @@ describe('doStream', () => {
15121512
});
15131513
});
15141514

1515+
describe('Azure text (fixture)', () => {
1516+
beforeEach(() => {
1517+
prepareChunksFixtureResponse('azure-text');
1518+
});
1519+
1520+
it('should stream text content with Azure SSE format', async () => {
1521+
const { stream } = await model.doStream({
1522+
prompt: TEST_PROMPT,
1523+
includeRawChunks: false,
1524+
});
1525+
1526+
expect(await convertReadableStreamToArray(stream)).toMatchSnapshot();
1527+
});
1528+
});
1529+
15151530
describe('tool call (fixture)', () => {
15161531
beforeEach(() => {
15171532
prepareChunksFixtureResponse('xai-tool-call');

0 commit comments

Comments
 (0)