rephrasal
Rephraser
Class to create rephrase inputs for a list of input prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_prompts
|
list[dict]
|
A list of dictionaries containing the input prompt dictionaries to rephrase. |
required |
template_prompts
|
list[str]
|
A dictionary containing the template prompt strings to be used for the rephrase LLMs. The keys should be the name of the template and the value should be the template. The string templates (the values) are to be used to format the prompt for the rephrase LLMs. Often contains placeholders for the input prompt (INPUT_PROMPT) which will be formatted with the prompt from the input prompt dict |
required |
rephrase_settings
|
dict
|
A dictionary of rephrase settings with the keys “api”, “model_name”, “parameters”. Used to define the rephrase LLMs to be used in the judging process |
required |
Source code in src/prompto/rephrasal.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 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 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
check_rephrase_model_in_rephrase_settings
staticmethod
check_rephrase_model_in_rephrase_settings(
rephrase_model: str | list[str], rephrase_settings: dict[str, dict]
) -> bool
Method to check if the rephrase(s) are in the rephrase settings dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rephrase_model
|
str | list[str]
|
A list of models or a single model to be used for rephrasals. These must be keys in the rephrase settings dictionary, otherwise a KeyError will be raised |
required |
rephrase_settings
|
dict[str, dict]
|
A dictionary of rephrase settings with the keys “api”, “model_name”, “parameters”. Used to define the rephrase LLMs to be used in the judging process |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the rephrase(s) are in the rephrase settings dictionary. Errors will be raised if the rephrase(s) are not in the dictionary |
Source code in src/prompto/rephrasal.py
check_rephrase_settings
staticmethod
Method to check if the rephrase settings dictionary is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rephrase_settings
|
dict
|
A dictionary of rephrase settings with the keys “api”, “model_name”, “parameters”. Used to define the rephrase LLMs to be used in the judging process |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the rephrase settings dictionary is valid. Errors will be raised if the dictionary is invalid |
Source code in src/prompto/rephrasal.py
create_new_input_file
create_new_input_file(
keep_original: bool,
completed_rephrase_responses: list[dict],
out_filepath: str,
parser: Callable | None = None,
) -> list[dict]
Method to create a new input file given the original input prompts and the completed rephrase responses. This is done by matching the “input-id” key in the rephrase responses with the “id” key in the input prompts.
There is an option to keep the original input prompts, or to remove them (i.e. only keep the rephrased prompts).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keep_original
|
bool
|
Whether or not to keep the original input prompts in the new input file. If True, the original input prompts will be kept in the new input file |
required |
completed_rephrase_responses
|
list[dict]
|
A list of dictionaries containing the completed rephrased prompts. Each dictionary should usually contain the keys “id”, “prompt”, “input-prompt” and “input-id”. They should also contain “input-api”, “input-model_name” and “input-parameters” keys |
required |
out_filepath
|
str
|
The path to the output file where the new input prompts will be saved as a jsonl file |
required |
parser
|
Callable
|
A parser function to apply to the rephrased prompt response. This function should take a string and return a string or a list of strings. If None, no parser will be applied to the rephrased prompt response |
None
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of dictionaries containing the input prompts for the models after rephrasing. The prompt will be the rephrased prompt, and there will be “input-id” and “input-prompt” keys to keep track of the original input prompt. The “id” key will indicate the rephrased prompt id. The “api”, “model_name”, and other keys from the original input will be restored |
Source code in src/prompto/rephrasal.py
create_rephrase_file
Method to create a rephrase file (as a jsonl file) containing the input prompt dictionaries to be processed by the model(s) for rephrasals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rephrase_model
|
list[str] | str
|
A list of models or a single model to be used for rephrasals. These must be keys in the rephrase settings dictionary, otherwise a KeyError will be raised |
required |
out_filepath
|
str
|
The path to the output file where the rephrase inputs will be saved as a jsonl file |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of dictionaries containing the input prompt for the LLM(s) for rephrasal. Each dictionary will contain a new prompt for rephrasal for each input prompt in the input_prompts list using the template_prompt |
Source code in src/prompto/rephrasal.py
create_rephrase_inputs
Method to create a list of input prompt dictionaries to be processed by the model(s) for rephrasals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rephrase_model
|
list[str] | str
|
A list of models or a single model to be used for rephrasals. These must be keys in the rephrase settings dictionary, otherwise a KeyError will be raised |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of dictionaries containing the input prompt for the LLM(s) for rephrasal. Each dictionary will contain a new prompt for rephrasal for each input prompt in the input_prompts list using the template_prompt |
Source code in src/prompto/rephrasal.py
load_rephrase_folder
load_rephrase_folder(
rephrase_folder: str, templates: str = "template.txt"
) -> tuple[list[str], dict]
Parses the rephrase_folder to load the template prompt string and rephrase settings dictionary.
The rephrase_folder should be a path to the rephrase folder containing the template files and settings.json files.
We read the template from rephrase_folder/template.txt and the settings from rephrase_folder/settings.json. If either of these files do not exist, a FileNotFoundError will be raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rephrase_folder
|
str
|
Path to the rephrase folder containing the template files and settings.json files |
required |
templates
|
str
|
Path to the template file to be used for the rephrasals. Each line in the template file should contain a template for the rephrasal prompt with {INPUT_PROMPT} as a placeholder. By default, this is ‘template.txt’. This file must be in the rephrase folder and end with ‘.txt’ |
'template.txt'
|
Returns:
| Type | Description |
|---|---|
tuple[list[str], dict]
|
A tuple containing the template prompt string, which are given as a list of strings and the rephrase settings dictionary |