Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
fix: carry logprobs and mark the cut-off item incomplete on /v1/responses (#1020)
Krisztian Gajdar6ce1634f7750
diff --git a/conformance/openai_generation/responses_request_vectors.json b/conformance/openai_generation/responses_request_vectors.jsondeleted file mode 100644index d95c18edb..000000000--- a/conformance/openai_generation/responses_request_vectors.json+++ /dev/null@@ -1,158 +0,0 @@-{- "accepted": [- {- "name": "string defaults",- "body": {"model": "m", "input": "Tell me a joke"},- "expected": {- "model": "m",- "prompt": "Tell me a joke",- "messages": null,- "max_output_tokens": 16,- "temperature": null,- "top_p": null,- "seed": null- }- },- {- "name": "developer and text parts",- "body": {- "model": "m",- "input": [- {"role": "developer", "content": "Be concise"},- {- "role": "user",- "content": [- {"type": "input_text", "text": "Hi "},- {"type": "text", "text": "there"}- ]- }- ],- "stream": false- },- "expected": {- "model": "m",- "prompt": null,- "messages": [- {"role": "system", "content": "Be concise"},- {"role": "user", "content": "Hi there"}- ],- "max_output_tokens": 16,- "temperature": null,- "top_p": null,- "seed": null- }- },- {- "name": "sampling overrides",- "body": {- "model": "m",- "input": "x",- "max_output_tokens": 32,- "temperature": 0.25,- "top_p": 0.8,- "seed": -1- },- "expected": {- "model": "m",- "prompt": "x",- "messages": null,- "max_output_tokens": 32,- "temperature": 0.25,- "top_p": 0.8,- "seed": -1- }- }- ],- "rejected": [- {- "name": "known unsupported tools",- "body": {"model": "m", "input": "x", "tools": []},- "param": "tools",- "code": "unsupported_field"- },- {- "name": "unknown top-level field",- "body": {"model": "m", "input": "x", "foo": true},- "param": "foo",- "code": "unsupported_field"- },- {- "name": "empty message array",- "body": {"model": "m", "input": []},- "param": "input",- "code": "invalid_request"- },- {- "name": "unknown message field",- "body": {"model": "m", "input": [{"role": "user", "content": "x", "name": "caller"}]},- "param": "input[0].name",- "code": "unsupported_field"- },- {- "name": "unknown content-part field",- "body": {- "model": "m",- "input": [{"role": "user", "content": [{"type": "input_text", "text": "x", "foo": true}]}]- },- "param": "input[0].content[0].foo",- "code": "unsupported_field"- },- {- "name": "non-text content part",- "body": {- "model": "m",- "input": [{"role": "user", "content": [{"type": "input_image", "text": "x"}]}]- },- "param": "input[0].content[0].type",- "code": "unsupported_field"- },- {- "name": "missing role",- "body": {"model": "m", "input": [{"content": "x"}]},- "param": "input[0].role",- "code": "invalid_request"- },- {- "name": "tool role without tool-output support",- "body": {"model": "m", "input": [{"role": "tool", "content": "x"}]},- "param": "input[0].role",- "code": "invalid_request"- },- {- "name": "streaming unsupported",- "body": {"model": "m", "input": "x", "stream": true},- "param": "stream",- "code": "unsupported_field"- },- {- "name": "stream type",- "body": {"model": "m", "input": "x", "stream": "false"},- "param": "stream",- "code": "invalid_request"- },- {- "name": "zero top p",- "body": {"model": "m", "input": "x", "top_p": 0},- "param": "top_p",- "code": "invalid_request"- },- {- "name": "temperature exceeds runtime precision",- "body": {"model": "m", "input": "x", "temperature": 1e100},- "param": "temperature",- "code": "invalid_request"- },- {- "name": "seed outside signed i64",- "body": {"model": "m", "input": "x", "seed": 9223372036854775808},- "param": "seed",- "code": "invalid_request"- },- {- "name": "invalid output cap",- "body": {"model": "m", "input": "x", "max_output_tokens": 0},- "param": "max_output_tokens",- "code": "invalid_request"- }- ]-}diff --git a/conformance/openai_responses/README.md b/conformance/openai_responses/README.mdindex b379018b2..5a6f2c1f4 100644--- a/conformance/openai_responses/README.md+++ b/conformance/openai_responses/README.md@@ -158,7 +158,7 @@ A chat completion with the content `"Hello."` for request `r1` becomes:"parallel_tool_calls": true, "tool_choice": "auto","output": [{"type": "message", "id": "msg-r1", "role": "assistant", "status": "completed",- "content": [{"type": "output_text", "text": "Hello.", "annotations": []}]}+ "content": [{"type": "output_text", "text": "Hello.", "annotations": [], "logprobs": []}]}],"usage": {"input_tokens": 10, "input_tokens_details": {"cached_tokens": 0},@@ -170,13 +170,16 @@ A chat completion with the content `"Hello."` for request `r1` becomes:`model` is the model the request named. `parallel_tool_calls` and`tool_choice` echo the request as sent, defaulting to `true` and `"auto"`. `output` holds a `message` item with one `output_text`-part when the chat content is non-empty, then one item per tool call: a+part, whose `annotations` and `logprobs` are empty lists, when the chat content+is non-empty, then one item per tool call: a`function_call` with the arguments string, or a `custom_tool_call` whose`input` is the `input` string of the arguments, or the raw arguments when theyare not a JSON object with a string `input`. The finish reasons `length` and`content_filter` make the response `incomplete` with`incomplete_details.reason` `max_output_tokens` or `content_filter`; every-other finish reason (`stop`, `tool_calls` or any other value) completes it. Usage is `input_tokens`, `input_tokens_details.cached_tokens`,+other finish reason (`stop`, `tool_calls` or any other value) completes it.+In an `incomplete` response the last output item, the one the finish cut off,+has `status: "incomplete"`; the items before it are `completed`. Usage is `input_tokens`, `input_tokens_details.cached_tokens`,`output_tokens`, `output_tokens_details.reasoning_tokens` and `total_tokens`from the chat usage, with absent details counted as 0.@@ -190,7 +193,8 @@ carries `type`, equal to the event name, and `sequence_number`, counting from`output` and `usage: null` until the terminal event. `output_item.added` and`output_item.done` carry `output_index` and `item`. The other item events carry`item_id` and `output_index`, and the text and content-part events also carry-`content_index: 0`.+`content_index: 0`. `output_text.delta` and `output_text.done` carry+`logprobs: []`, as every `output_text` part does.1. `response.created` and `response.in_progress` open the stream.2. The first non-empty text delta adds the message item and its `output_text`@@ -209,7 +213,10 @@ carries `type`, equal to the event name, and `sequence_number`, counting from5. After the usage chunk and `[DONE]`, `response.completed` (or`response.incomplete` for a `length` or `content_filter` finish) carries thefull answer; a chat stream that closes after a finish without `[DONE]` ends- the same way. The stream ends there, without a `[DONE]` frame of its own.+ the same way. On a `length` or `content_filter` finish, the item open when+ the finish arrives closes with `status: "incomplete"`, in its+ `output_item.done` and in the terminal response; the items closed before it+ stay `completed`. The stream ends there, without a `[DONE]` frame of its own.6. A chat error chunk after the stream opened becomes `response.failed` with`status: "failed"`, `error: {"code", "message"}` from the chat error, theitems completed so far as `output` (an item still open is left out) anddiff --git a/conformance/openai_responses/response_vectors.json b/conformance/openai_responses/response_vectors.jsonindex 61e862628..e720b08a6 100644--- a/conformance/openai_responses/response_vectors.json+++ b/conformance/openai_responses/response_vectors.json@@ -29,7 +29,7 @@"id": "msg-r1","role": "assistant","status": "completed",- "content": [{"type": "output_text", "text": "Hello.", "annotations": []}]+ "content": [{"type": "output_text", "text": "Hello.", "annotations": [], "logprobs": []}]}],"usage": {@@ -93,7 +93,7 @@"id": "msg-r2","role": "assistant","status": "completed",- "content": [{"type": "output_text", "text": "Running both.", "annotations": []}]+ "content": [{"type": "output_text", "text": "Running both.", "annotations": [], "logprobs": []}]},{"type": "function_call",@@ -329,8 +329,8 @@"type": "message","id": "msg-r6","role": "assistant",- "status": "completed",- "content": [{"type": "output_text", "text": "Once upon a time", "annotations": []}]+ "status": "incomplete",+ "content": [{"type": "output_text", "text": "Once upon a time", "annotations": [], "logprobs": []}]}],"usage": {@@ -404,7 +404,7 @@"id": "msg-r8","role": "assistant","status": "completed",- "content": [{"type": "output_text", "text": "42", "annotations": []}]+ "content": [{"type": "output_text", "text": "42", "annotations": [], "logprobs": []}]}],"usage": {@@ -571,7 +571,7 @@"id": "msg-r11","role": "assistant","status": "completed",- "content": [{"type": "output_text", "text": "\n\n", "annotations": []}]+ "content": [{"type": "output_text", "text": "\n\n", "annotations": [], "logprobs": []}]},{"type": "function_call", "id": "fc-r11-0", "call_id": "call_1", "name": "exec_command", "arguments": "{\"cmd\":\"ls\"}", "status": "completed"}],@@ -610,7 +610,7 @@"id": "msg-r12","role": "assistant","status": "completed",- "content": [{"type": "output_text", "text": "Hello.", "annotations": []}]+ "content": [{"type": "output_text", "text": "Hello.", "annotations": [], "logprobs": []}]}],"usage": {@@ -621,6 +621,67 @@"total_tokens": 13}}+ },+ {+ "name": "length cutting off a function call leaves the message completed and the call incomplete",+ "model": "m",+ "request_id": "r13",+ "request": {+ "model": "m",+ "input": "List the files.",+ "tools": [+ {+ "type": "function",+ "name": "exec_command",+ "description": "Run a shell command.",+ "parameters": {"type": "object", "properties": {"cmd": {"type": "string"}}, "required": ["cmd"]}+ }+ ],+ "max_output_tokens": 12+ },+ "chat": {+ "choices": [+ {+ "index": 0,+ "message": {+ "role": "assistant",+ "content": "Checking.",+ "tool_calls": [{"id": "call_1", "type": "function", "function": {"name": "exec_command", "arguments": "{\"cmd\":\"l"}}]+ },+ "finish_reason": "length"+ }+ ],+ "usage": {"prompt_tokens": 12, "completion_tokens": 12, "total_tokens": 24}+ },+ "response": {+ "id": "resp-r13",+ "object": "response",+ "created_at": 0,+ "model": "m",+ "status": "incomplete",+ "incomplete_details": {"reason": "max_output_tokens"},+ "error": null,+ "store": false,+ "parallel_tool_calls": true,+ "tool_choice": "auto",+ "output": [+ {+ "type": "message",+ "id": "msg-r13",+ "role": "assistant",+ "status": "completed",+ "content": [{"type": "output_text", "text": "Checking.", "annotations": [], "logprobs": []}]+ },+ {"type": "function_call", "id": "fc-r13-0", "call_id": "call_1", "name": "exec_command", "arguments": "{\"cmd\":\"l", "status": "incomplete"}+ ],+ "usage": {+ "input_tokens": 12,+ "input_tokens_details": {"cached_tokens": 0},+ "output_tokens": 12,+ "output_tokens_details": {"reasoning_tokens": 0},+ "total_tokens": 24+ }+ }}]}diff --git a/conformance/openai_responses/stream_vectors.json b/conformance/openai_responses/stream_vectors.jsonindex d0c663369..47b96d34e 100644--- a/conformance/openai_responses/stream_vectors.json+++ b/conformance/openai_responses/stream_vectors.json@@ -133,7 +133,8 @@"part": {"type": "output_text","text": "",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -145,7 +146,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "Hel"+ "delta": "Hel",+ "logprobs": []}},{@@ -156,7 +158,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "lo"+ "delta": "lo",+ "logprobs": []}},{@@ -167,7 +170,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "text": "Hello"+ "text": "Hello",+ "logprobs": []}},{@@ -181,7 +185,8 @@"part": {"type": "output_text","text": "Hello",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -200,7 +205,8 @@{"type": "output_text","text": "Hello",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -232,7 +238,8 @@{"type": "output_text","text": "Hello",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -446,7 +453,8 @@"part": {"type": "output_text","text": "",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -458,7 +466,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "Let me look."+ "delta": "Let me look.",+ "logprobs": []}},{@@ -469,7 +478,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "text": "Let me look."+ "text": "Let me look.",+ "logprobs": []}},{@@ -483,7 +493,8 @@"part": {"type": "output_text","text": "Let me look.",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -502,7 +513,8 @@{"type": "output_text","text": "Let me look.",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -596,7 +608,8 @@{"type": "output_text","text": "Let me look.",- "annotations": []+ "annotations": [],+ "logprobs": []}]},@@ -1308,7 +1321,8 @@"part": {"type": "output_text","text": "",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -1320,7 +1334,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "Once upon"+ "delta": "Once upon",+ "logprobs": []}},{@@ -1331,7 +1346,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": " a time"+ "delta": " a time",+ "logprobs": []}},{@@ -1342,7 +1358,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "text": "Once upon a time"+ "text": "Once upon a time",+ "logprobs": []}},{@@ -1356,7 +1373,8 @@"part": {"type": "output_text","text": "Once upon a time",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -1370,12 +1388,13 @@"type": "message","id": "msg-r","role": "assistant",- "status": "completed",+ "status": "incomplete","content": [{"type": "output_text","text": "Once upon a time",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -1404,12 +1423,13 @@"type": "message","id": "msg-r","role": "assistant",- "status": "completed",+ "status": "incomplete","content": [{"type": "output_text","text": "Once upon a time",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -1430,6 +1450,361 @@}]},+ {+ "name": "length cutting off a tool call closes the message completed and the call incomplete",+ "request_id": "r",+ "model": "m",+ "request": {+ "model": "m",+ "input": "List the files.",+ "stream": true,+ "tools": [+ {+ "type": "function",+ "name": "exec_command",+ "description": "Run a shell command.",+ "parameters": {+ "type": "object",+ "properties": {+ "cmd": {+ "type": "string"+ }+ },+ "required": [+ "cmd"+ ]+ }+ }+ ],+ "max_output_tokens": 12+ },+ "frames": [+ {+ "choices": [+ {+ "index": 0,+ "delta": {+ "role": "assistant",+ "content": "Checking."+ },+ "finish_reason": null+ }+ ]+ },+ {+ "choices": [+ {+ "index": 0,+ "delta": {+ "tool_calls": [+ {+ "index": 0,+ "id": "call_1",+ "type": "function",+ "function": {+ "name": "exec_command",+ "arguments": "{\"cmd\":"+ }+ }+ ]+ },+ "finish_reason": null+ }+ ]+ },+ {+ "choices": [+ {+ "index": 0,+ "delta": {+ "tool_calls": [+ {+ "index": 0,+ "function": {+ "arguments": "\"l"+ }+ }+ ]+ },+ "finish_reason": null+ }+ ]+ },+ {+ "choices": [+ {+ "index": 0,+ "delta": {},+ "finish_reason": "length"+ }+ ]+ },+ {+ "choices": [],+ "usage": {+ "prompt_tokens": 12,+ "completion_tokens": 12,+ "total_tokens": 24+ }+ },+ "[DONE]"+ ],+ "events": [+ {+ "event": "response.created",+ "data": {+ "type": "response.created",+ "sequence_number": 0,+ "response": {+ "id": "resp-r",+ "object": "response",+ "created_at": 0,+ "model": "m",+ "status": "in_progress",+ "incomplete_details": null,+ "error": null,+ "store": false,+ "parallel_tool_calls": true,+ "tool_choice": "auto",+ "output": [],+ "usage": null+ }+ }+ },+ {+ "event": "response.in_progress",+ "data": {+ "type": "response.in_progress",+ "sequence_number": 1,+ "response": {+ "id": "resp-r",+ "object": "response",+ "created_at": 0,+ "model": "m",+ "status": "in_progress",+ "incomplete_details": null,+ "error": null,+ "store": false,+ "parallel_tool_calls": true,+ "tool_choice": "auto",+ "output": [],+ "usage": null+ }+ }+ },+ {+ "event": "response.output_item.added",+ "data": {+ "type": "response.output_item.added",+ "sequence_number": 2,+ "output_index": 0,+ "item": {+ "type": "message",+ "id": "msg-r",+ "role": "assistant",+ "status": "in_progress",+ "content": []+ }+ }+ },+ {+ "event": "response.content_part.added",+ "data": {+ "type": "response.content_part.added",+ "sequence_number": 3,+ "item_id": "msg-r",+ "output_index": 0,+ "content_index": 0,+ "part": {+ "type": "output_text",+ "text": "",+ "annotations": [],+ "logprobs": []+ }+ }+ },+ {+ "event": "response.output_text.delta",+ "data": {+ "type": "response.output_text.delta",+ "sequence_number": 4,+ "item_id": "msg-r",+ "output_index": 0,+ "content_index": 0,+ "delta": "Checking.",+ "logprobs": []+ }+ },+ {+ "event": "response.output_text.done",+ "data": {+ "type": "response.output_text.done",+ "sequence_number": 5,+ "item_id": "msg-r",+ "output_index": 0,+ "content_index": 0,+ "text": "Checking.",+ "logprobs": []+ }+ },+ {+ "event": "response.content_part.done",+ "data": {+ "type": "response.content_part.done",+ "sequence_number": 6,+ "item_id": "msg-r",+ "output_index": 0,+ "content_index": 0,+ "part": {+ "type": "output_text",+ "text": "Checking.",+ "annotations": [],+ "logprobs": []+ }+ }+ },+ {+ "event": "response.output_item.done",+ "data": {+ "type": "response.output_item.done",+ "sequence_number": 7,+ "output_index": 0,+ "item": {+ "type": "message",+ "id": "msg-r",+ "role": "assistant",+ "status": "completed",+ "content": [+ {+ "type": "output_text",+ "text": "Checking.",+ "annotations": [],+ "logprobs": []+ }+ ]+ }+ }+ },+ {+ "event": "response.output_item.added",+ "data": {+ "type": "response.output_item.added",+ "sequence_number": 8,+ "output_index": 1,+ "item": {+ "type": "function_call",+ "id": "fc-r-0",+ "call_id": "call_1",+ "name": "exec_command",+ "arguments": "",+ "status": "in_progress"+ }+ }+ },+ {+ "event": "response.function_call_arguments.delta",+ "data": {+ "type": "response.function_call_arguments.delta",+ "sequence_number": 9,+ "item_id": "fc-r-0",+ "output_index": 1,+ "delta": "{\"cmd\":"+ }+ },+ {+ "event": "response.function_call_arguments.delta",+ "data": {+ "type": "response.function_call_arguments.delta",+ "sequence_number": 10,+ "item_id": "fc-r-0",+ "output_index": 1,+ "delta": "\"l"+ }+ },+ {+ "event": "response.function_call_arguments.done",+ "data": {+ "type": "response.function_call_arguments.done",+ "sequence_number": 11,+ "item_id": "fc-r-0",+ "output_index": 1,+ "arguments": "{\"cmd\":\"l"+ }+ },+ {+ "event": "response.output_item.done",+ "data": {+ "type": "response.output_item.done",+ "sequence_number": 12,+ "output_index": 1,+ "item": {+ "type": "function_call",+ "id": "fc-r-0",+ "call_id": "call_1",+ "name": "exec_command",+ "arguments": "{\"cmd\":\"l",+ "status": "incomplete"+ }+ }+ },+ {+ "event": "response.incomplete",+ "data": {+ "type": "response.incomplete",+ "sequence_number": 13,+ "response": {+ "id": "resp-r",+ "object": "response",+ "created_at": 0,+ "model": "m",+ "status": "incomplete",+ "incomplete_details": {+ "reason": "max_output_tokens"+ },+ "error": null,+ "store": false,+ "parallel_tool_calls": true,+ "tool_choice": "auto",+ "output": [+ {+ "type": "message",+ "id": "msg-r",+ "role": "assistant",+ "status": "completed",+ "content": [+ {+ "type": "output_text",+ "text": "Checking.",+ "annotations": [],+ "logprobs": []+ }+ ]+ },+ {+ "type": "function_call",+ "id": "fc-r-0",+ "call_id": "call_1",+ "name": "exec_command",+ "arguments": "{\"cmd\":\"l",+ "status": "incomplete"+ }+ ],+ "usage": {+ "input_tokens": 12,+ "input_tokens_details": {+ "cached_tokens": 0+ },+ "output_tokens": 12,+ "output_tokens_details": {+ "reasoning_tokens": 0+ },+ "total_tokens": 24+ }+ }+ }+ }+ ]+ },{"name": "error frame after output fails the response","request_id": "r",@@ -1538,7 +1913,8 @@"part": {"type": "output_text","text": "",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -1550,7 +1926,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "par"+ "delta": "par",+ "logprobs": []}},{@@ -1847,7 +2224,8 @@"part": {"type": "output_text","text": "",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -1859,7 +2237,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "Listing."+ "delta": "Listing.",+ "logprobs": []}},{@@ -1870,7 +2249,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "text": "Listing."+ "text": "Listing.",+ "logprobs": []}},{@@ -1884,7 +2264,8 @@"part": {"type": "output_text","text": "Listing.",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -1903,7 +2284,8 @@{"type": "output_text","text": "Listing.",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -1987,7 +2369,8 @@"part": {"type": "output_text","text": "",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -1999,7 +2382,8 @@"item_id": "msg-r-2","output_index": 2,"content_index": 0,- "delta": "Waiting for "+ "delta": "Waiting for ",+ "logprobs": []}},{@@ -2010,7 +2394,8 @@"item_id": "msg-r-2","output_index": 2,"content_index": 0,- "delta": "the output."+ "delta": "the output.",+ "logprobs": []}},{@@ -2021,7 +2406,8 @@"item_id": "msg-r-2","output_index": 2,"content_index": 0,- "text": "Waiting for the output."+ "text": "Waiting for the output.",+ "logprobs": []}},{@@ -2035,7 +2421,8 @@"part": {"type": "output_text","text": "Waiting for the output.",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -2054,7 +2441,8 @@{"type": "output_text","text": "Waiting for the output.",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -2086,7 +2474,8 @@{"type": "output_text","text": "Listing.",- "annotations": []+ "annotations": [],+ "logprobs": []}]},@@ -2107,7 +2496,8 @@{"type": "output_text","text": "Waiting for the output.",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -2474,7 +2864,8 @@"part": {"type": "output_text","text": "",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -2486,7 +2877,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "par"+ "delta": "par",+ "logprobs": []}},{@@ -2497,7 +2889,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "tial"+ "delta": "tial",+ "logprobs": []}},{@@ -2625,7 +3018,8 @@"part": {"type": "output_text","text": "",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -2637,7 +3031,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "Hello."+ "delta": "Hello.",+ "logprobs": []}},{@@ -2648,7 +3043,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "text": "Hello."+ "text": "Hello.",+ "logprobs": []}},{@@ -2662,7 +3058,8 @@"part": {"type": "output_text","text": "Hello.",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -2681,7 +3078,8 @@{"type": "output_text","text": "Hello.",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -2713,7 +3111,8 @@{"type": "output_text","text": "Hello.",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -2843,7 +3242,8 @@"part": {"type": "output_text","text": "",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -2855,7 +3255,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "Hello."+ "delta": "Hello.",+ "logprobs": []}},{@@ -2866,7 +3267,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "text": "Hello."+ "text": "Hello.",+ "logprobs": []}},{@@ -2880,7 +3282,8 @@"part": {"type": "output_text","text": "Hello.",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -2899,7 +3302,8 @@{"type": "output_text","text": "Hello.",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -2931,7 +3335,8 @@{"type": "output_text","text": "Hello.",- "annotations": []+ "annotations": [],+ "logprobs": []}]}@@ -3361,7 +3766,8 @@"part": {"type": "output_text","text": "",- "annotations": []+ "annotations": [],+ "logprobs": []}}},@@ -3373,7 +3779,8 @@"item_id": "msg-r","output_index": 0,"content_index": 0,- "delta": "Running."+ "delta": "Running.",+ "logprobs": []}},{diff --git a/packages/sie_gateway/src/handlers/responses/response.rs b/packages/sie_gateway/src/handlers/responses/response.rsindex 718b462a6..f77074502 100644--- a/packages/sie_gateway/src/handlers/responses/response.rs+++ b/packages/sie_gateway/src/handlers/responses/response.rs@@ -98,12 +98,17 @@ impl ResponseShell {}}+/// An `output_text` content part.+pub(crate) fn output_text(text: &str) -> Value {+ json!({"type": "output_text", "text": text, "annotations": [], "logprobs": []})+}+/// A `message` item. An item still in progress has no content yet.pub(crate) fn message_item(id: &str, text: &str, status: &str) -> Value {- let content = if status == "completed" {- json!([{"type": "output_text", "text": text, "annotations": []}])- } else {+ let content = if status == "in_progress" {json!([])+ } else {+ json!([output_text(text)])};json!({"type": "message",@@ -202,6 +207,9 @@ pub(crate) fn chat_completion_to_response(}let (status, incomplete_details) =status_for(choice.get("finish_reason").and_then(Value::as_str));+ if let Some(last) = output.last_mut() {+ last["status"] = json!(status);+ }let usage = chat.get("usage").and_then(responses_usage)diff --git a/packages/sie_gateway/src/handlers/responses/stream.rs b/packages/sie_gateway/src/handlers/responses/stream.rsindex 6f64da7b9..0f199f481 100644--- a/packages/sie_gateway/src/handlers/responses/stream.rs+++ b/packages/sie_gateway/src/handlers/responses/stream.rs@@ -16,7 +16,9 @@ use bytes::Bytes;use futures_util::StreamExt;use serde_json::{json, Map, Value};-use super::response::{custom_input, message_item, responses_usage, status_for, ResponseShell};+use super::response::{+ custom_input, message_item, output_text, responses_usage, status_for, ResponseShell,+};pub(crate) const FAILED: &str = "response.failed";const SERVER_ERROR: &str = "server_error";@@ -172,9 +174,9 @@ impl StreamMachine {}}if let Some(finish_reason) = choice.get("finish_reason").and_then(Value::as_str) {+ self.finish_reason = Some(finish_reason.to_string());self.close_text(&mut events);self.close_call(&mut events);- self.finish_reason = Some(finish_reason.to_string());}}if let Some(usage) = chunk.get("usage").filter(|usage| usage.is_object()) {@@ -272,7 +274,7 @@ impl StreamMachine {"item_id": item_id,"output_index": output_index,"content_index": 0,- "part": {"type": "output_text", "text": "", "annotations": []},+ "part": output_text(""),}),);events.extend([added, part]);@@ -291,6 +293,7 @@ impl StreamMachine {"output_index": open.output_index,"content_index": 0,"delta": text,+ "logprobs": [],});let event = self.event("response.output_text.delta", payload);events.push(event);@@ -300,7 +303,8 @@ impl StreamMachine {let Some(open) = self.text.take() else {return;};- let item = message_item(&open.item_id, &open.text, "completed");+ let status = status_for(self.finish_reason.as_deref()).0;+ let item = message_item(&open.item_id, &open.text, status);let text_done = self.event("response.output_text.done",json!({@@ -308,6 +312,7 @@ impl StreamMachine {"output_index": open.output_index,"content_index": 0,"text": open.text,+ "logprobs": [],}),);let part_done = self.event(@@ -316,7 +321,7 @@ impl StreamMachine {"item_id": open.item_id,"output_index": open.output_index,"content_index": 0,- "part": {"type": "output_text", "text": open.text, "annotations": []},+ "part": output_text(&open.text),}),);let item_done = self.event(@@ -423,7 +428,7 @@ impl StreamMachine {&open.call_id,&open.name,&value,- "completed",+ status_for(self.finish_reason.as_deref()).0,);let done = self.event("response.output_item.done",diff --git a/packages/sie_gateway/src/handlers/responses/tests.rs b/packages/sie_gateway/src/handlers/responses/tests.rsindex afe439c7d..7e9cba3dc 100644--- a/packages/sie_gateway/src/handlers/responses/tests.rs+++ b/packages/sie_gateway/src/handlers/responses/tests.rs@@ -528,7 +528,13 @@ fn assert_event_grammar(events: &[Value], context: &str) {assert_eq!(data["output_index"], index, "{context}");assert_eq!(data["item"]["id"], id, "{context}");assert_eq!(data["item"]["type"], kind.as_str(), "{context}");- assert_eq!(data["item"]["status"], "completed", "{context}");+ assert!(+ matches!(+ data["item"]["status"].as_str(),+ Some("completed" | "incomplete")+ ),+ "{context}"+ );done.push(data["item"].clone());continue;}@@ -818,7 +824,7 @@ async fn a_buffered_response_is_served_by_the_chat_route() {"id": "msg-request-1","role": "assistant","status": "completed",- "content": [{"type": "output_text", "text": "ok", "annotations": []}],+ "content": [{"type": "output_text", "text": "ok", "annotations": [], "logprobs": []}],}],"usage": {"input_tokens": 1,diff --git a/packages/sie_server/src/sie_server/api/responses_translation.py b/packages/sie_server/src/sie_server/api/responses_translation.pyindex 0f936f695..8f96df150 100644--- a/packages/sie_server/src/sie_server/api/responses_translation.py+++ b/packages/sie_server/src/sie_server/api/responses_translation.py@@ -681,23 +681,27 @@ def response_object(}-def _message_item(item_id: str, text: str | None) -> dict[str, Any]:+def _output_text(text: str) -> dict[str, Any]:+ return {"type": "output_text", "text": text, "annotations": [], "logprobs": []}+++def _message_item(item_id: str, text: str | None, status: str = "completed") -> dict[str, Any]:"""A message item, ``in_progress`` and empty while ``text`` is None."""return {"type": "message","id": item_id,"role": "assistant",- "status": "in_progress" if text is None else "completed",- "content": [] if text is None else [{"type": "output_text", "text": text, "annotations": []}],+ "status": "in_progress" if text is None else status,+ "content": [] if text is None else [_output_text(text)],}-def _call_item(item_id: str, call_id: str, name: str, value: str, *, custom: bool, done: bool) -> dict[str, Any]:+def _call_item(item_id: str, call_id: str, name: str, value: str, *, custom: bool, status: str) -> dict[str, Any]:if custom:payload = {"type": "custom_tool_call", "id": item_id, "call_id": call_id, "name": name, "input": value}else:payload = {"type": "function_call", "id": item_id, "call_id": call_id, "name": name, "arguments": value}- return {**payload, "status": "completed" if done else "in_progress"}+ return {**payload, "status": status}def _call_item_id(request_id: str, position: int, *, custom: bool) -> str:@@ -736,8 +740,10 @@ def chat_completion_to_response(chat: Any, shape: ResponseShape, request_id: strcustom = name in shape.custom_toolsvalue = custom_tool_input(arguments) if custom else argumentsitem_id = _call_item_id(request_id, position, custom=custom)- output.append(_call_item(item_id, call_id, name, value, custom=custom, done=True))+ output.append(_call_item(item_id, call_id, name, value, custom=custom, status="completed"))status, incomplete = _status(choice.get("finish_reason"))+ if output:+ output[-1]["status"] = statusreturn response_object(shape,request_id,@@ -911,7 +917,7 @@ class StreamMachine:item_id=item_id,output_index=index,content_index=0,- part={"type": "output_text", "text": "", "annotations": []},+ part=_output_text(""),))self._text.text += text@@ -922,6 +928,7 @@ class StreamMachine:output_index=self._text.output_index,content_index=0,delta=text,+ logprobs=[],))@@ -930,10 +937,17 @@ class StreamMachine:returnopened, self._text = self._text, Noneitem_id, index, text = opened.item_id, opened.output_index, opened.text- part = {"type": "output_text", "text": text, "annotations": []}- item = _message_item(item_id, text)+ part = _output_text(text)+ item = _message_item(item_id, text, _status(self._finish_reason)[0])events.append(- self._event("response.output_text.done", item_id=item_id, output_index=index, content_index=0, text=text)+ self._event(+ "response.output_text.done",+ item_id=item_id,+ output_index=index,+ content_index=0,+ text=text,+ logprobs=[],+ ))events.append(self._event("response.content_part.done", item_id=item_id, output_index=index, content_index=0, part=part)@@ -963,7 +977,7 @@ class StreamMachine:self._call = _OpenCall(chat_index, self._calls, self._next_index, item_id, call_id, name, custom)self._calls += 1self._next_index += 1- item = _call_item(item_id, call_id, name, "", custom=custom, done=False)+ item = _call_item(item_id, call_id, name, "", custom=custom, status="in_progress")events.append(self._event("response.output_item.added", output_index=self._call.output_index, item=item))if not fragment:return None@@ -999,7 +1013,9 @@ class StreamMachine:"response.function_call_arguments.done", item_id=item_id, output_index=index, arguments=value))- item = _call_item(item_id, opened.call_id, opened.name, value, custom=opened.custom, done=True)+ item = _call_item(+ item_id, opened.call_id, opened.name, value, custom=opened.custom, status=_status(self._finish_reason)[0]+ )events.append(self._event("response.output_item.done", output_index=index, item=item))self._output.append(item)self._closed_calls.add(opened.chat_index)diff --git a/packages/sie_server/tests/api/test_openai_responses_route.py b/packages/sie_server/tests/api/test_openai_responses_route.pyindex 9dd9d1f85..ffeb3ba1f 100644--- a/packages/sie_server/tests/api/test_openai_responses_route.py+++ b/packages/sie_server/tests/api/test_openai_responses_route.py@@ -190,7 +190,12 @@ def test_a_buffered_response_matches_the_chat_answer_to_the_same_conversation(cl"role": "assistant","status": "completed","content": [- {"type": "output_text", "text": chat["choices"][0]["message"]["content"], "annotations": []}+ {+ "type": "output_text",+ "text": chat["choices"][0]["message"]["content"],+ "annotations": [],+ "logprobs": [],+ }],}],diff --git a/packages/sie_server/tests/api/test_responses_translation.py b/packages/sie_server/tests/api/test_responses_translation.pyindex 7df7b6df1..aafac9b38 100644--- a/packages/sie_server/tests/api/test_responses_translation.py+++ b/packages/sie_server/tests/api/test_responses_translation.py@@ -292,11 +292,13 @@ def _assert_event_grammar(events: list[dict[str, Any]], context: str) -> None:``response.created`` and ``response.in_progress``, then one item at a timewith contiguous output indices and the events of its kind, then one- terminal event, and nothing after. Sequence numbers count from 0.+ terminal event whose output is the items closed so far, and nothing after.+ Sequence numbers count from 0."""assert [event["data"]["sequence_number"] for event in events] == list(range(len(events))), contextassert [event["event"] for event in events[:2]] == ["response.created", "response.in_progress"], contextopen_item: tuple[int, str] | None = None+ closed: list[dict[str, Any]] = []next_index = 0allowed = {"message": {@@ -314,8 +316,8 @@ def _assert_event_grammar(events: list[dict[str, Any]], context: str) -> None:assert position == len(events) - 1, f"{context}: event after the end"if name != "response.failed":assert open_item is None, f"{context}: {name} with an open item"- items = data["response"]["output"]- assert [item["status"] for item in items] == ["completed"] * len(items), context+ assert data["response"]["output"] == closed, context+ assert {item["status"] for item in closed} <= {"completed", "incomplete"}, contextreturnif name == "response.output_item.added":assert open_item is None, f"{context}: two open items"@@ -325,6 +327,7 @@ def _assert_event_grammar(events: list[dict[str, Any]], context: str) -> None:elif name == "response.output_item.done":assert open_item is not None, contextassert (data["output_index"], data["item"]["type"]) == open_item, context+ closed.append(data["item"])open_item = Noneelse:assert open_item is not None, f"{context}: {name} without an open item"