Datasets:
Download code/schemas/prompt.py from govtech/municipalbench-full: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/datasets/govtech/municipalbench-full/resolve/main/code/schemas/prompt.py
- Command line
-
hf download hf://datasets/govtech/municipalbench-full/code/schemas/prompt.py
-
curl -L -o prompt.py https://huggingface.co/datasets/govtech/municipalbench-full/resolve/main/code/schemas/prompt.py
1.18 kB
| """Model-agnostic logical prompt passed to inference adapters.""" | |
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| from dataclasses import dataclass, replace | |
| class PromptBundle: | |
| group_id: str | |
| group_name: str | |
| category_ids: tuple[str, ...] | |
| category_names: tuple[str, ...] | |
| system_text: str | |
| user_text: str | |
| max_per_category: int = 10 | |
| max_per_pass: int = 50 | |
| max_new_tokens: int = 3072 | |
| def prompt_hash(self) -> str: | |
| payload = { | |
| "group_id": self.group_id, "category_ids": self.category_ids, | |
| "system_text": self.system_text, "user_text": self.user_text, | |
| "max_per_category": self.max_per_category, "max_per_pass": self.max_per_pass, | |
| } | |
| return hashlib.sha256(json.dumps(payload, sort_keys=True).encode()).hexdigest() | |
| def combined_text(self) -> str: | |
| return f"{self.system_text}\n\n{self.user_text}" | |
| def class_prompt(self) -> str: | |
| return ",".join(self.category_names) | |
| def with_max_new_tokens(self, value: int) -> "PromptBundle": | |
| return replace(self, max_new_tokens=value) | |