Download code/test_response_format.py from harry1332/agentbench-avalon-sampled-cpu-trace: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/datasets/harry1332/agentbench-avalon-sampled-cpu-trace/resolve/main/code/test_response_format.py
- Command line
-
hf download hf://datasets/harry1332/agentbench-avalon-sampled-cpu-trace/code/test_response_format.py
-
curl -L -o test_response_format.py https://huggingface.co/datasets/harry1332/agentbench-avalon-sampled-cpu-trace/resolve/main/code/test_response_format.py
1.37 kB
| import unittest | |
| from response_format import validate_answer | |
| class ResponseFormatTest(unittest.TestCase): | |
| def test_valid_outputs(self): | |
| for kind, answer in [('vote', 'Answer: Yes'), ('team', 'Answer: [0, 2, 3]'), | |
| ('assassination', 'Answer: [4]'), | |
| ('probabilities', 'Answer: {0: 0.5, 1: 0, 2: 1, 3: 0.2, 4: 0.8}')]: | |
| validate_answer(kind, answer) | |
| def test_rejects_original_failure(self): | |
| with self.assertRaises(ValueError): | |
| validate_answer('probabilities', 'Answer: {0: 0.5, 1: 0.5, 2: 0.5, 3: 0.5, 4: 0.5}\n\nAs an AI assistant, I have no access.') | |
| def test_rejects_invalid_or_executable_answers(self): | |
| for kind, answer in [('probabilities', 'Answer: __import__("os").getcwd()'), | |
| ('probabilities', 'Answer: {0: 0.5}'), | |
| ('probabilities', 'Answer: {0: 2, 1: 0, 2: 0, 3: 0, 4: 0}'), | |
| ('team', 'Answer: [[1]]'), ('team', 'Answer: [1, 1]'), | |
| ('team', 'Answer: [5]'), ('vote', 'Answer: Yes, but No'), | |
| ('assassination', 'Answer: [1, 2]')]: | |
| with self.subTest(answer=answer), self.assertRaises(ValueError): | |
| validate_answer(kind, answer) | |
| if __name__ == '__main__': | |
| unittest.main() | |