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

Method _generate

opencompass/models/gemini_api.py:91–199  ·  view source on GitHub ↗

Generate results given an input. Args: inputs (PromptType): A string or PromptDict. The PromptDict should be organized in OpenCompass' API format. max_out_len (int): The maximum length of the output. Returns: str:

(
        self,
        input: PromptType,
        max_out_len: int = 512,
    )

Source from the content-addressed store, hash-verified

89 return results
90
91 def _generate(
92 self,
93 input: PromptType,
94 max_out_len: int = 512,
95 ) -> str:
96 """Generate results given an input.
97
98 Args:
99 inputs (PromptType): A string or PromptDict.
100 The PromptDict should be organized in OpenCompass'
101 API format.
102 max_out_len (int): The maximum length of the output.
103
104 Returns:
105 str: The generated string.
106 """
107 assert isinstance(input, (str, PromptList))
108
109 if isinstance(input, str):
110 messages = [{'role': 'user', 'parts': [{'text': input}]}]
111 else:
112 messages = []
113 system_prompt = None
114 for item in input:
115 if item['role'] == 'SYSTEM':
116 system_prompt = item['prompt']
117 for item in input:
118 if system_prompt is not None:
119 msg = {
120 'parts': [{
121 'text': system_prompt + '\n' + item['prompt']
122 }]
123 }
124 else:
125 msg = {'parts': [{'text': item['prompt']}]}
126 if item['role'] == 'HUMAN':
127 msg['role'] = 'user'
128 messages.append(msg)
129 elif item['role'] == 'BOT':
130 msg['role'] = 'model'
131 messages.append(msg)
132 elif item['role'] == 'SYSTEM':
133 pass
134
135 # model can be response with user and system
136 # when it comes with agent involved.
137 assert msg['role'] in ['user', 'system']
138
139 data = {
140 'model':
141 self.path,
142 'contents':
143 messages,
144 'safetySettings': [
145 {
146 'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
147 'threshold': 'BLOCK_NONE',
148 },

Callers

nothing calls this directly

Calls 2

postMethod · 0.80
waitMethod · 0.45

Tested by

no test coverage detected