diff --git a/src/openai/types/beta/beta_response_output_message_param.py b/src/openai/types/beta/beta_response_output_message_param.py index 0ac8a9c60e..9b89293bea 100644 --- a/src/openai/types/beta/beta_response_output_message_param.py +++ b/src/openai/types/beta/beta_response_output_message_param.py @@ -23,7 +23,7 @@ class Agent(TypedDict, total=False): class BetaResponseOutputMessageParam(TypedDict, total=False): """An output message from the model.""" - id: Required[str] + id: str """The unique ID of the output message.""" content: Required[Iterable[Content]] @@ -32,7 +32,7 @@ class BetaResponseOutputMessageParam(TypedDict, total=False): role: Required[Literal["assistant"]] """The role of the output message. Always `assistant`.""" - status: Required[Literal["in_progress", "completed", "incomplete"]] + status: Literal["in_progress", "completed", "incomplete"] """The status of the message input. One of `in_progress`, `completed`, or `incomplete`. Populated when input items diff --git a/src/openai/types/responses/response_output_message_param.py b/src/openai/types/responses/response_output_message_param.py index 4552d9bf1f..202c6bd03d 100644 --- a/src/openai/types/responses/response_output_message_param.py +++ b/src/openai/types/responses/response_output_message_param.py @@ -16,7 +16,7 @@ class ResponseOutputMessageParam(TypedDict, total=False): """An output message from the model.""" - id: Required[str] + id: str """The unique ID of the output message.""" content: Required[Iterable[Content]] @@ -25,7 +25,7 @@ class ResponseOutputMessageParam(TypedDict, total=False): role: Required[Literal["assistant"]] """The role of the output message. Always `assistant`.""" - status: Required[Literal["in_progress", "completed", "incomplete"]] + status: Literal["in_progress", "completed", "incomplete"] """The status of the message input. One of `in_progress`, `completed`, or `incomplete`. Populated when input items diff --git a/tests/test_response_output_message_param.py b/tests/test_response_output_message_param.py new file mode 100644 index 0000000000..cde45d868a --- /dev/null +++ b/tests/test_response_output_message_param.py @@ -0,0 +1,86 @@ +from __future__ import annotations + +from typing_extensions import assert_type + +from openai.types.beta import BetaResponseInputParam +from openai.types.responses import ResponseInputParam +from openai.types.beta.beta_response_output_message_param import BetaResponseOutputMessageParam +from openai.types.responses.response_output_message_param import ResponseOutputMessageParam + + +def test_response_output_message_param_id_and_status_are_optional() -> None: + # Client-authored assistant message turn without invented id or status + message: ResponseOutputMessageParam = { + "type": "message", + "role": "assistant", + "content": [ + { + "type": "output_text", + "text": "5", + "annotations": [], + }, + { + "type": "output_text", + "text": "something else?", + "annotations": [], + }, + ], + } + + assert_type(message, ResponseOutputMessageParam) + assert "id" not in message + assert "status" not in message + + # Fully valid within ResponseInputParam list + conversation: ResponseInputParam = [ + {"role": "user", "content": [{"type": "input_text", "text": "2+3=?"}]}, + message, + {"role": "user", "content": [{"type": "input_text", "text": "what's the square of the result?"}]}, + ] + assert len(conversation) == 3 + + +def test_response_output_message_param_with_id_and_status() -> None: + # Optional id and status are still accepted when provided + message: ResponseOutputMessageParam = { + "type": "message", + "id": "msg_123", + "status": "completed", + "role": "assistant", + "content": [ + { + "type": "output_text", + "text": "hello", + "annotations": [], + } + ], + } + + assert_type(message, ResponseOutputMessageParam) + assert message["id"] == "msg_123" + assert message["status"] == "completed" + + +def test_beta_response_output_message_param_id_and_status_are_optional() -> None: + # Client-authored assistant message turn without invented id or status + message: BetaResponseOutputMessageParam = { + "type": "message", + "role": "assistant", + "content": [ + { + "type": "output_text", + "text": "5", + "annotations": [], + }, + ], + } + + assert_type(message, BetaResponseOutputMessageParam) + assert "id" not in message + assert "status" not in message + + conversation: BetaResponseInputParam = [ + {"role": "user", "content": [{"type": "input_text", "text": "hello"}]}, + message, + ] + assert len(conversation) == 2