MCPcopy Create free account
hub / github.com/InternScience/SciReason / _split_rounds

Method _split_rounds

opencompass/models/base.py:396–421  ·  view source on GitHub ↗

Split the prompt template into rounds, based on single round template. Return the index ranges of each round. Specifically, prompt_template[res[i]:res[i+1]] represents the i-th round in the template.

(
            self, prompt_template: List[Union[str, Dict]],
            single_round_template: List[Union[str, Dict]])

Source from the content-addressed store, hash-verified

394 return prompt
395
396 def _split_rounds(
397 self, prompt_template: List[Union[str, Dict]],
398 single_round_template: List[Union[str, Dict]]) -> List[int]:
399 """Split the prompt template into rounds, based on single round
400 template.
401
402 Return the index ranges of each round. Specifically,
403 prompt_template[res[i]:res[i+1]] represents the i-th round in the
404 template.
405 """
406 role_idxs = {
407 role_cfg['role']: i
408 for i, role_cfg in enumerate(single_round_template)
409 if not isinstance(role_cfg, str)
410 }
411 last_role_idx = -1
412 cutoff_idxs = [0]
413 for idx, template in enumerate(prompt_template):
414 if isinstance(template, str):
415 continue
416 role_idx = role_idxs[template['role']]
417 if role_idx <= last_role_idx:
418 cutoff_idxs.append(idx)
419 last_role_idx = role_idx
420 cutoff_idxs.append(len(prompt_template))
421 return cutoff_idxs
422
423 def _update_role_dict(self, prompt: Union[List, str,
424 Dict]) -> Dict[str, Dict]:

Callers 1

parse_templateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected