|
| 1 | +import pytest |
| 2 | + |
| 3 | +from labelbox.schema.tool_building.classification import Classification |
| 4 | +from labelbox.schema.tool_building.prompt_issue_tool import PromptIssueTool |
| 5 | + |
| 6 | + |
| 7 | +def test_as_dict(): |
| 8 | + tool = PromptIssueTool(name="Prompt Issue Tool") |
| 9 | + |
| 10 | + # Get the dictionary representation |
| 11 | + tool_dict = tool.asdict() |
| 12 | + expected_dict = { |
| 13 | + "tool": "prompt-issue", |
| 14 | + "name": "Prompt Issue Tool", |
| 15 | + "required": False, |
| 16 | + "schemaNodeId": None, |
| 17 | + "featureSchemaId": None, |
| 18 | + "classifications": [ |
| 19 | + { |
| 20 | + "type": "checklist", |
| 21 | + "instructions": "prompt_issue", |
| 22 | + "name": "prompt_issue", |
| 23 | + "required": False, |
| 24 | + "options": [ |
| 25 | + { |
| 26 | + "schemaNodeId": None, |
| 27 | + "featureSchemaId": None, |
| 28 | + "label": "This prompt cannot be rated (eg. contains PII, a nonsense prompt, a foreign language, or other scenario that makes the responses impossible to assess reliably). However, if you simply do not have expertise to tackle this prompt, please skip the task; do not mark it as not rateable.", |
| 29 | + "value": "not_rateable", |
| 30 | + "options": [], |
| 31 | + }, |
| 32 | + { |
| 33 | + "schemaNodeId": None, |
| 34 | + "featureSchemaId": None, |
| 35 | + "label": "This prompt contains a false, offensive, or controversial premise (eg. “why does 1+1=3”?)", |
| 36 | + "value": "false_offensive_controversial", |
| 37 | + "options": [], |
| 38 | + }, |
| 39 | + { |
| 40 | + "schemaNodeId": None, |
| 41 | + "featureSchemaId": None, |
| 42 | + "label": "This prompt is not self-contained, i.e. the prompt cannot be understood without additional context about previous turns, account information or images.", |
| 43 | + "value": "not_self_contained", |
| 44 | + "options": [], |
| 45 | + }, |
| 46 | + ], |
| 47 | + "schemaNodeId": None, |
| 48 | + "featureSchemaId": None, |
| 49 | + "scope": "global", |
| 50 | + } |
| 51 | + ], |
| 52 | + "color": None, |
| 53 | + } |
| 54 | + assert tool_dict == expected_dict |
| 55 | + |
| 56 | + with pytest.raises(ValueError): |
| 57 | + tool.classifications = [ |
| 58 | + Classification(Classification.Type.TEXT, "prompt_issue") |
| 59 | + ] |
| 60 | + |
| 61 | + with pytest.raises(ValueError): |
| 62 | + tool.classifications = "abcd" |
| 63 | + |
| 64 | + # Test that we can modify the classification options |
| 65 | + classification = tool.classifications[0] |
| 66 | + classification.options.pop() |
| 67 | + classification.options[0].label = "test" |
| 68 | + classification.options[0].value == "test_value" |
| 69 | + tool.classifications = [classification] |
| 70 | + assert tool.classifications == [classification] |
0 commit comments