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
4 changes: 2 additions & 2 deletions src/openai/types/beta/beta_response_output_message_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/openai/types/responses/response_output_message_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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
Expand Down
86 changes: 86 additions & 0 deletions tests/test_response_output_message_param.py
Original file line number Diff line number Diff line change
@@ -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