Split the response into sections based on the answer keys.
(answer_keys:List[str], response:str)
| 10 | logger = logging.getLogger(__name__) |
| 11 | |
| 12 | def split_answer_section(answer_keys:List[str], response:str) -> Dict[str, str]: |
| 13 | """ |
| 14 | Split the response into sections based on the answer keys. |
| 15 | """ |
| 16 | current_section = None |
| 17 | answer = {} |
| 18 | for line in response.splitlines(): |
| 19 | is_key_flag = False |
| 20 | for key in answer_keys: |
| 21 | if line.startswith(key): |
| 22 | current_section = key |
| 23 | answer[key] = line[len(key)+1:].strip() |
| 24 | is_key_flag = True |
| 25 | break |
| 26 | if not is_key_flag and current_section is not None: |
| 27 | answer[current_section] += line |
| 28 | |
| 29 | return answer |
| 30 | |
| 31 | def try_to_handle_too_long_code(render_target_func:Callable, code_segments:List[str], statements:List[str], *args) -> List[str]: |
| 32 | """ |