|
63 | 63 | _create_usage_metadata_responses,
|
64 | 64 | _format_message_content,
|
65 | 65 | _get_last_messages,
|
| 66 | + _make_computer_call_output_from_message, |
66 | 67 | _oai_structured_outputs_parser,
|
67 | 68 | )
|
68 | 69 |
|
@@ -2454,3 +2455,76 @@ def test_get_request_payload_use_previous_response_id() -> None:
|
2454 | 2455 | payload = llm._get_request_payload(messages)
|
2455 | 2456 | assert "previous_response_id" not in payload
|
2456 | 2457 | assert len(payload["input"]) == 1
|
| 2458 | + |
| 2459 | + |
| 2460 | +def test_make_computer_call_output_from_message() -> None: |
| 2461 | + # List content |
| 2462 | + tool_message = ToolMessage( |
| 2463 | + content=[ |
| 2464 | + {"type": "input_image", "image_url": "data:image/png;base64,<image_data>"} |
| 2465 | + ], |
| 2466 | + tool_call_id="call_abc123", |
| 2467 | + additional_kwargs={"type": "computer_call_output"}, |
| 2468 | + ) |
| 2469 | + result = _make_computer_call_output_from_message(tool_message) |
| 2470 | + |
| 2471 | + assert result == { |
| 2472 | + "type": "computer_call_output", |
| 2473 | + "call_id": "call_abc123", |
| 2474 | + "output": { |
| 2475 | + "type": "input_image", |
| 2476 | + "image_url": "data:image/png;base64,<image_data>", |
| 2477 | + }, |
| 2478 | + } |
| 2479 | + |
| 2480 | + # String content |
| 2481 | + tool_message = ToolMessage( |
| 2482 | + content="data:image/png;base64,<image_data>", |
| 2483 | + tool_call_id="call_abc123", |
| 2484 | + additional_kwargs={"type": "computer_call_output"}, |
| 2485 | + ) |
| 2486 | + result = _make_computer_call_output_from_message(tool_message) |
| 2487 | + |
| 2488 | + assert result == { |
| 2489 | + "type": "computer_call_output", |
| 2490 | + "call_id": "call_abc123", |
| 2491 | + "output": { |
| 2492 | + "type": "input_image", |
| 2493 | + "image_url": "data:image/png;base64,<image_data>", |
| 2494 | + }, |
| 2495 | + } |
| 2496 | + |
| 2497 | + # Safety checks |
| 2498 | + tool_message = ToolMessage( |
| 2499 | + content=[ |
| 2500 | + {"type": "input_image", "image_url": "data:image/png;base64,<image_data>"} |
| 2501 | + ], |
| 2502 | + tool_call_id="call_abc123", |
| 2503 | + additional_kwargs={ |
| 2504 | + "type": "computer_call_output", |
| 2505 | + "acknowledged_safety_checks": [ |
| 2506 | + { |
| 2507 | + "id": "cu_sc_abc234", |
| 2508 | + "code": "malicious_instructions", |
| 2509 | + "message": "Malicious instructions detected.", |
| 2510 | + } |
| 2511 | + ], |
| 2512 | + }, |
| 2513 | + ) |
| 2514 | + result = _make_computer_call_output_from_message(tool_message) |
| 2515 | + |
| 2516 | + assert result == { |
| 2517 | + "type": "computer_call_output", |
| 2518 | + "call_id": "call_abc123", |
| 2519 | + "output": { |
| 2520 | + "type": "input_image", |
| 2521 | + "image_url": "data:image/png;base64,<image_data>", |
| 2522 | + }, |
| 2523 | + "acknowledged_safety_checks": [ |
| 2524 | + { |
| 2525 | + "id": "cu_sc_abc234", |
| 2526 | + "code": "malicious_instructions", |
| 2527 | + "message": "Malicious instructions detected.", |
| 2528 | + } |
| 2529 | + ], |
| 2530 | + } |
0 commit comments