|
| 1 | +""" |
| 2 | +Test to verify that message fields are properly filtered before sending to API. |
| 3 | +
|
| 4 | +This test verifies that unsupported fields like 'weight', 'control_plane_step', |
| 5 | +and 'reasoning_content' are excluded from messages when preparing API requests. |
| 6 | +""" |
| 7 | + |
| 8 | +from eval_protocol.models import Message |
| 9 | + |
| 10 | + |
| 11 | +def test_dump_model_excludes_unsupported_fields(): |
| 12 | + """Test that dump_mdoel_for_chat_completion_request excludes unsupported fields.""" |
| 13 | + # Create a message with all possible fields including unsupported ones |
| 14 | + message = Message( |
| 15 | + role="user", |
| 16 | + content="Hello", |
| 17 | + weight=0, |
| 18 | + control_plane_step={"step": 1}, |
| 19 | + reasoning_content="Some reasoning", |
| 20 | + name="test_user", |
| 21 | + ) |
| 22 | + |
| 23 | + # Get the filtered dictionary |
| 24 | + filtered = message.dump_mdoel_for_chat_completion_request() |
| 25 | + |
| 26 | + # Verify unsupported fields are excluded |
| 27 | + assert "weight" not in filtered, "weight field should be excluded" |
| 28 | + assert "control_plane_step" not in filtered, "control_plane_step field should be excluded" |
| 29 | + assert "reasoning_content" not in filtered, "reasoning_content field should be excluded" |
| 30 | + |
| 31 | + # Verify supported fields are included |
| 32 | + assert "role" in filtered, "role field should be included" |
| 33 | + assert "content" in filtered, "content field should be included" |
| 34 | + assert filtered["role"] == "user" |
| 35 | + assert filtered["content"] == "Hello" |
| 36 | + |
| 37 | + # Verify name is included (it's a supported field for tool calls) |
| 38 | + assert "name" in filtered |
| 39 | + assert filtered["name"] == "test_user" |
| 40 | + |
| 41 | + |
| 42 | +def test_dump_model_with_only_supported_fields(): |
| 43 | + """Test that supported fields are preserved.""" |
| 44 | + message = Message( |
| 45 | + role="assistant", |
| 46 | + content="I can help you", |
| 47 | + tool_calls=None, |
| 48 | + tool_call_id=None, |
| 49 | + ) |
| 50 | + |
| 51 | + filtered = message.dump_mdoel_for_chat_completion_request() |
| 52 | + |
| 53 | + # Should only contain supported fields |
| 54 | + assert filtered["role"] == "assistant" |
| 55 | + assert filtered["content"] == "I can help you" |
| 56 | + |
| 57 | + # Should not contain unsupported fields even if None |
| 58 | + assert "weight" not in filtered |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == "__main__": |
| 62 | + import pytest |
| 63 | + |
| 64 | + pytest.main([__file__, "-v"]) |
0 commit comments