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)
| 393 | return res, cont |
| 394 | |
| 395 | def _role2api_role(self, |
| 396 | role_prompt: Dict, |
| 397 | role_dict: Dict[str, Dict], |
| 398 | for_gen: bool = False) -> Tuple[Dict, bool]: |
| 399 | """Convert a role prompt to a string, given an updated role_dict. |
| 400 | |
| 401 | Args: |
| 402 | role_prompt (Dict): The role prompt to be converted. |
| 403 | role_dict (Dict[str, Dict]): The updated role dict. |
| 404 | for_gen (bool): If True, the prompts will be converted for |
| 405 | generation tasks. The conversion stops before the first |
| 406 | role whose "generate" is set to True. |
| 407 | |
| 408 | Returns: |
| 409 | Tuple[Dict, bool]: The converted string, and whether the follow-up |
| 410 | conversion should be proceeded. |
| 411 | """ |
| 412 | merged_prompt = role_dict.get( |
| 413 | role_prompt['role'], |
| 414 | role_dict.get(role_prompt.get('fallback_role'))) |
| 415 | # res_api_prompt = dict(type='', ) |
| 416 | if for_gen and merged_prompt.get('generate', False): |
| 417 | return None, False |
| 418 | res = {} |
| 419 | res['role'] = merged_prompt['api_role'] |
| 420 | res['prompt'] = merged_prompt.get('begin', '') |
| 421 | res['prompt'] += merged_prompt.get('prompt', '') |
| 422 | res['prompt'] += merged_prompt.get('end', '') |
| 423 | return res, True |
| 424 | |
| 425 | |
| 426 | class TokenBucket: |