|
56 | 56 | ] |
57 | 57 |
|
58 | 58 |
|
59 | | -def make_replayed_response_output() -> list[object]: |
60 | | - response = parse_obj( |
| 59 | +def make_replayed_response() -> Response: |
| 60 | + return parse_obj( |
61 | 61 | Response, |
62 | 62 | { |
63 | 63 | "id": "resp_123", |
@@ -101,7 +101,10 @@ def make_replayed_response_output() -> list[object]: |
101 | 101 | "tools": [], |
102 | 102 | }, |
103 | 103 | ) |
104 | | - return response.output |
| 104 | + |
| 105 | + |
| 106 | +def make_replayed_response_output() -> list[object]: |
| 107 | + return make_replayed_response().output |
105 | 108 |
|
106 | 109 |
|
107 | 110 | @pytest.mark.respx(base_url=base_url) |
@@ -156,6 +159,40 @@ def test_response_output_items_can_be_replayed_without_null_only_fields( |
156 | 159 | assert request_body["input"] == EXPECTED_REPLAYED_OUTPUT_INPUT |
157 | 160 |
|
158 | 161 |
|
| 162 | +@pytest.mark.respx(base_url=base_url) |
| 163 | +def test_output_as_input_can_be_replayed_without_losing_phase( |
| 164 | + client: OpenAI, |
| 165 | + respx_mock: MockRouter, |
| 166 | +) -> None: |
| 167 | + route = respx_mock.post("/responses").mock( |
| 168 | + return_value=httpx.Response( |
| 169 | + 200, |
| 170 | + json={ |
| 171 | + "id": "resp_456", |
| 172 | + "object": "response", |
| 173 | + "created_at": 0, |
| 174 | + "model": "gpt-4o-mini", |
| 175 | + "output": [], |
| 176 | + "parallel_tool_calls": True, |
| 177 | + "tool_choice": "auto", |
| 178 | + "tools": [], |
| 179 | + }, |
| 180 | + ) |
| 181 | + ) |
| 182 | + |
| 183 | + replayed_response = make_replayed_response() |
| 184 | + |
| 185 | + response = client.responses.create( |
| 186 | + model="gpt-4o-mini", |
| 187 | + input=replayed_response.output_as_input, |
| 188 | + ) |
| 189 | + |
| 190 | + assert isinstance(response, Response) |
| 191 | + |
| 192 | + request_body = json.loads(route.calls[0].request.content.decode("utf-8")) |
| 193 | + assert request_body["input"] == EXPECTED_REPLAYED_OUTPUT_INPUT |
| 194 | + |
| 195 | + |
159 | 196 | @pytest.mark.respx(base_url=base_url) |
160 | 197 | async def test_async_replayed_response_output_items_can_be_counted_without_null_only_fields( |
161 | 198 | async_client: AsyncOpenAI, |
|
0 commit comments