MCPcopy Create free account
hub / github.com/OpenBMB/BMTools / __complete

Method __complete

bmtools/tools/database/utils/llm.py:171–189  ·  view source on GitHub ↗

Generates text from the model and returns the log prob data.

(self, prompt, n)

Source from the content-addressed store, hash-verified

169 return [response['choices'][i]['text'] for i in range(len(response['choices']))]
170
171 def __complete(self, prompt, n):
172 """Generates text from the model and returns the log prob data."""
173 if not isinstance(prompt, list):
174 text = [prompt]
175 config = self.config['gpt_config'].copy()
176 config['n'] = n
177 # If there are any [APE] tokens in the prompts, remove them
178 for i in range(len(prompt)):
179 prompt[i] = prompt[i].replace('[APE]', '').strip()
180 response = None
181 while response is None:
182 try:
183 response = openai.Completion.create(
184 **config, prompt=prompt)
185 except Exception as e:
186 print(e)
187 print('Retrying...')
188 time.sleep(5)
189 return response['choices']
190
191 def __log_probs(self, text, log_prob_range=None):
192 """Returns the log probs of the text."""

Callers 1

completeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected