Set prompt ID automatically.
(self, name, value)
| 50 | original_prompt: str = '' # the unformatted prompt (needed to recover instruction for AlpacaEval) |
| 51 | |
| 52 | def __setattr__(self, name, value): |
| 53 | """Set prompt ID automatically.""" |
| 54 | if name == 'prompt' and value is not None: |
| 55 | content = '' |
| 56 | |
| 57 | for turn in value: |
| 58 | if "role" not in turn: |
| 59 | raise ValueError("every turn in an example must have a 'role' field") |
| 60 | |
| 61 | if "content" not in turn: |
| 62 | raise ValueError("every turn in an example must have a 'content' field") |
| 63 | |
| 64 | content = content + turn['content'] |
| 65 | |
| 66 | self.prompt_id = hashlib.sha256(content.encode()).hexdigest() |
| 67 | |
| 68 | super().__setattr__(name, value) |
| 69 | |
| 70 | def __getitem__(self, key): |
| 71 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected