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

Method _generate

opencompass/models/openai_api.py:192–378  ·  view source on GitHub ↗

Generate results given a list of inputs. 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. temperature (fl

(self, input: PromptType, max_out_len: int,
                  temperature: float)

Source from the content-addressed store, hash-verified

190 return results
191
192 def _generate(self, input: PromptType, max_out_len: int,
193 temperature: float) -> str:
194 """Generate results given a list of inputs.
195
196 Args:
197 inputs (PromptType): A string or PromptDict.
198 The PromptDict should be organized in OpenCompass'
199 API format.
200 max_out_len (int): The maximum length of the output.
201 temperature (float): What sampling temperature to use,
202 between 0 and 2. Higher values like 0.8 will make the output
203 more random, while lower values like 0.2 will make it more
204 focused and deterministic.
205
206 Returns:
207 str: The generated string.
208 """
209 assert isinstance(input, (str, PromptList))
210
211 messages, max_out_len = self._preprocess_messages(
212 input, max_out_len, self.max_seq_len, self.mode,
213 self.get_token_len)
214
215 max_num_retries = 0
216 while max_num_retries < self.retry:
217 self.wait()
218
219 with Lock():
220 if len(self.invalid_keys) == len(self.keys):
221 raise RuntimeError('All keys have insufficient quota.')
222
223 # find the next valid key
224 while True:
225 self.key_ctr += 1
226 if self.key_ctr == len(self.keys):
227 self.key_ctr = 0
228
229 if self.keys[self.key_ctr] not in self.invalid_keys:
230 break
231
232 key = self.keys[self.key_ctr]
233
234 header = {
235 'Authorization': f'Bearer {key}',
236 'content-type': 'application/json',
237 'api-key': key,
238 }
239
240 if self.orgs:
241 with Lock():
242 self.org_ctr += 1
243 if self.org_ctr == len(self.orgs):
244 self.org_ctr = 0
245 header['OpenAI-Organization'] = self.orgs[self.org_ctr]
246
247 try:
248 if any(model in self.path for model in O1_MODEL_LIST):
249 self.logger.warning(

Callers 1

run_judge_pairMethod · 0.95

Calls 6

_preprocess_messagesMethod · 0.95
updateMethod · 0.80
postMethod · 0.80
decodeMethod · 0.80
getMethod · 0.80
waitMethod · 0.45

Tested by

no test coverage detected