Convert a role prompt to a string, given an updated role_dict. Args: role_prompt (Dict): The role prompt to be converted. role_dict (Dict[str, Dict]): The updated role dict. for_gen (bool): If True, the prompts will be converted for genera
(self,
role_prompt: Dict,
role_dict: Dict[str, Dict],
for_gen: bool = False)
| 473 | return res, cont |
| 474 | |
| 475 | def _role2str(self, |
| 476 | role_prompt: Dict, |
| 477 | role_dict: Dict[str, Dict], |
| 478 | for_gen: bool = False) -> Tuple[str, bool]: |
| 479 | """Convert a role prompt to a string, given an updated role_dict. |
| 480 | |
| 481 | Args: |
| 482 | role_prompt (Dict): The role prompt to be converted. |
| 483 | role_dict (Dict[str, Dict]): The updated role dict. |
| 484 | for_gen (bool): If True, the prompts will be converted for |
| 485 | generation tasks. The conversion stops before the first |
| 486 | role whose "generate" is set to True. |
| 487 | |
| 488 | Returns: |
| 489 | Tuple[str, bool]: The converted string, and whether the follow-up |
| 490 | conversion should be proceeded. |
| 491 | """ |
| 492 | merged_prompt = role_dict.get( |
| 493 | role_prompt['role'], |
| 494 | role_dict.get(role_prompt.get('fallback_role'))) |
| 495 | res = merged_prompt.get('begin', '') |
| 496 | if for_gen and merged_prompt.get('generate', False): |
| 497 | return res, False |
| 498 | # res += merged_prompt.get('prompt', '') + merged_prompt.get('end', '') |
| 499 | res += merged_prompt.get('prompt', '') + merged_prompt.get('end', '') |
| 500 | return res, True |
| 501 | |
| 502 | def _encode_speical_tokens(self, prompt: List[Union[str, int]]) -> str: |
| 503 | """Encode the special tokens in the prompt. |