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

Method _prompt2api

opencompass/models/base_api.py:356–393  ·  view source on GitHub ↗

Convert the prompts to a API-style prompts, given an updated role_dict. Args: prompts (Union[List, str]): The prompts to be converted. role_dict (Dict[str, Dict]): The updated role dict. for_gen (bool): If True, the prompts will be converted for

(self,
                    prompts: Union[List, str],
                    role_dict: Dict[str, Dict],
                    for_gen: bool = False)

Source from the content-addressed store, hash-verified

354 return cutoff_idxs
355
356 def _prompt2api(self,
357 prompts: Union[List, str],
358 role_dict: Dict[str, Dict],
359 for_gen: bool = False) -> Tuple[List, bool]:
360 """Convert the prompts to a API-style prompts, given an updated
361 role_dict.
362
363 Args:
364 prompts (Union[List, str]): The prompts to be converted.
365 role_dict (Dict[str, Dict]): The updated role dict.
366 for_gen (bool): If True, the prompts will be converted for
367 generation tasks. The conversion stops before the first
368 role whose "generate" is set to True.
369
370 Returns:
371 Tuple[List, bool]: The converted string, and whether the follow-up
372 conversion should be proceeded.
373 """
374 cont = True
375 if isinstance(prompts, str):
376 return prompts, cont
377 elif isinstance(prompts, dict):
378 api_role, cont = self._role2api_role(prompts, role_dict, for_gen)
379 return api_role, cont
380
381 res = []
382 for prompt in prompts:
383 if isinstance(prompt, str):
384 raise TypeError('Mixing str without explicit role is not '
385 'allowed in API models!')
386 else:
387 api_role, cont = self._role2api_role(prompt, role_dict,
388 for_gen)
389 if api_role:
390 res.append(api_role)
391 if not cont:
392 break
393 return res, cont
394
395 def _role2api_role(self,
396 role_prompt: Dict,

Callers 1

parse_templateMethod · 0.95

Calls 1

_role2api_roleMethod · 0.95

Tested by

no test coverage detected