text_model_write_processor
Validation and transformation for text model write operations.
Enforces the same rules that scripts/legacy_text/convert.py applies: - Settings keys validated against generation_params.json - Tags auto-generated from style + parameter size - display_name auto-generated if not provided - model_name extracted from entry key - parameters normalized to int
Used by both the API write path and the GitHub sync validator.
LegacyRecordValue
LegacyRecordValue = (
str
| int
| float
| bool
| list[int]
| list[float]
| list[str]
| SettingsDict
| None
)
TextModelWriteProcessor
Validates and transforms text model records on write operations.
Enforces convert.py rules: 1. Settings keys must exist in generation_params.json 2. Parameters must be a positive integer 3. Tags auto-generated: existing + style + size bucket (e.g., "7B") 4. display_name auto-generated from model name if not provided 5. model_name field populated by splitting entry key on "/"
Source code in src/horde_model_reference/text_model_write_processor.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
__init__
Initialize the processor with bundled validation data.
validate_and_transform
validate_and_transform(
entry_key: str,
record: LegacyRecordDict,
*,
apply_defaults: bool = True,
) -> LegacyRecordDict
Validate and transform a single text model record.
Parameters:
-
entry_key(str) –The model name / dictionary key (used for error messages and naming).
-
record(LegacyRecordDict) –The record data to validate and transform.
-
apply_defaults(bool, default:True) –Whether to apply defaults.json values for missing fields.
Returns:
-
LegacyRecordDict–Validated and transformed record.
Raises:
-
ValueError–If validation fails (invalid settings keys, missing parameters, etc.)
Source code in src/horde_model_reference/text_model_write_processor.py
normalize_parameters
Ensure the parameters field is present and a positive integer.
Parameters:
-
entry_key(str) –Model name for error messages.
-
value(LegacyRecordValue) –The raw parameters value.
Returns:
-
int–Normalized integer parameter count.
Raises:
-
ValueError–If parameters is missing, non-numeric, or non-positive.
Source code in src/horde_model_reference/text_model_write_processor.py
normalize_settings
Validate and normalize the settings dict.
All keys must exist in generation_params.json.
Parameters:
-
entry_key(str) –Model name for error messages.
-
value(LegacyRecordValue) –The raw settings value (dict, JSON string, or None).
Returns:
-
SettingsDict | None–Normalized settings dict, or None if empty/absent.
Raises:
-
ValueError–If settings is not a dict or contains invalid keys.
Source code in src/horde_model_reference/text_model_write_processor.py
generate_tags
generate_tags(
*,
parameters: int,
existing_tags: LegacyRecordValue,
style_for_tag: LegacyRecordValue,
) -> list[str]
Generate tags following convert.py rules.
Includes existing tags, the style (if provided), and a size tag derived from the parameter count.
Parameters:
-
parameters(int) –The parameter count (used to derive size tag like "7B").
-
existing_tags(LegacyRecordValue) –Tags from the incoming record (list or comma-separated string).
-
style_for_tag(LegacyRecordValue) –Style value from the incoming record (added as tag if truthy).
Returns:
Source code in src/horde_model_reference/text_model_write_processor.py
extract_model_name
staticmethod
Extract model_name following convert.py's splitting logic.
For "Author/ModelName", returns "ModelName". For "ModelName", returns "ModelName".
Parameters:
-
entry_key(str) –The full model name / dict key.
Returns:
-
str–The model name portion (after the first "/" if present).
Raises:
-
ValueError–If
entry_keylooks like a URL (contains://).
Source code in src/horde_model_reference/text_model_write_processor.py
generate_display_name
staticmethod
Generate a human-readable display name from a model name.
Replaces hyphens and underscores with spaces, normalizes whitespace.
Parameters:
-
model_name(str) –The raw model name to convert.
Returns:
-
str–Human-readable display name.
Example
TextModelWriteProcessor.generate_display_name("llama-2-7b-chat") 'llama 2 7b chat'
Source code in src/horde_model_reference/text_model_write_processor.py
_load_bundled_json
Load a bundled JSON data file from the package data directory.
Falls back to scripts/legacy_text/ relative to the repository root when running from a source checkout.
Parameters:
-
filename(str) –The JSON filename to load (e.g., "generation_params.json").
Returns:
-
dict[str, LegacyRecordValue]–Parsed JSON data.
Raises:
-
FileNotFoundError–If the file cannot be located in either location.
Source code in src/horde_model_reference/text_model_write_processor.py
_get_generation_params
cached
Get the generation_params.json data, loading on first access.
Source code in src/horde_model_reference/text_model_write_processor.py
_get_defaults
cached
Get the defaults.json data, loading on first access.
Source code in src/horde_model_reference/text_model_write_processor.py
get_valid_settings_keys
Return the list of valid settings keys from generation_params.json.
Useful for frontend validation hints or API documentation.
Returns: