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

Method format

opencompass/utils/prompt.py:82–105  ·  view source on GitHub ↗

Replaces all instances of 'src' in the PromptList with 'dst'. Args: src (str): The string to be replaced. dst (PromptType): The string or PromptList to replace with. Returns: PromptList: A new PromptList with 'src' replaced by 'dst'. Rai

(self, **kwargs)

Source from the content-addressed store, hash-verified

80 """An enhanced list, used for intermidate representation of a prompt."""
81
82 def format(self, **kwargs) -> PromptList:
83 """Replaces all instances of 'src' in the PromptList with 'dst'.
84
85 Args:
86 src (str): The string to be replaced.
87 dst (PromptType): The string or PromptList to replace with.
88
89 Returns:
90 PromptList: A new PromptList with 'src' replaced by 'dst'.
91
92 Raises:
93 TypeError: If 'dst' is a PromptList and 'src' is in a dictionary's
94 'prompt' key.
95 """
96 new_list = PromptList()
97 for item in self:
98 if isinstance(item, Dict):
99 new_item = deepcopy(item)
100 if 'prompt' in item:
101 new_item['prompt'] = safe_format(item['prompt'], **kwargs)
102 new_list.append(new_item)
103 else:
104 new_list.append(safe_format(item, **kwargs))
105 return new_list
106
107 def replace(self, src: str, dst: Union[str, PromptList]) -> PromptList:
108 """Replaces all instances of 'src' in the PromptList with 'dst'.

Calls 2

PromptListClass · 0.85
safe_formatFunction · 0.85

Tested by 1

test_formatMethod · 0.76