Process results from OpenAI API response. :param response: dict OpenAI API Response :param ctxlen: int Length of context (so we can slice them away and only keep the predictions) :return: continuation_logprobs: np.array Log probabilities of continuati
(response, ctxlen)
| 8 | |
| 9 | |
| 10 | def get_result(response, ctxlen): |
| 11 | """Process results from OpenAI API response. |
| 12 | |
| 13 | :param response: dict |
| 14 | OpenAI API Response |
| 15 | :param ctxlen: int |
| 16 | Length of context (so we can slice them away and only keep the predictions) |
| 17 | :return: |
| 18 | continuation_logprobs: np.array |
| 19 | Log probabilities of continuation tokens |
| 20 | is_greedy: bool |
| 21 | whether argmax matches given continuation exactly |
| 22 | """ |
| 23 | is_greedy = True |
| 24 | logprobs = response["logprobs"]["token_logprobs"] |
| 25 | continuation_logprobs = sum(logprobs[ctxlen:]) |
| 26 | |
| 27 | for i in range(ctxlen, len(response["logprobs"]["tokens"])): |
| 28 | token = response["logprobs"]["tokens"][i] |
| 29 | top_tokens = response["logprobs"]["top_logprobs"][i] |
| 30 | top_token = max(top_tokens.keys(), key=lambda x: top_tokens[x]) |
| 31 | if top_token != token: |
| 32 | is_greedy = False |
| 33 | break |
| 34 | |
| 35 | return continuation_logprobs, is_greedy |
| 36 | |
| 37 | |
| 38 | def oa_completion(**kwargs): |
no test coverage detected