def _sample_choice(
      self, prompt: str, response: str) -> float:
    """Returns the log probability of the prompt and response."""
    original_prompt = prompt
    augmented_prompt = _ensure_prompt_not_too_long(prompt, len(response))
    attempts = 0
    for attempts in range(_MAX_ATTEMPTS):
      if attempts > 0:
        seconds_to_sleep = (_SECONDS_TO_SLEEP_WHEN_RATE_LIMITED +
                            random.uniform(-_JITTER_SECONDS, _JITTER_SECONDS))
        if attempts >= _NUM_SILENT_ATTEMPTS:
          print(
              f'Sleeping for {seconds_to_sleep} seconds.. '
              + f'attempt: {attempts} / {_MAX_ATTEMPTS}'
          )
        time.sleep(seconds_to_sleep)
      try:
        messages = [
            {
                'role': 'system',
                'content': (
                    'You always continue sentences provided '
                    + 'by the user and you never repeat what '
                    + 'the user already said.'
                ),
            },
            {
                'role': 'user',
                'content': 'Question: Is Jake a turtle?\nAnswer: Jake is ',
            },
            {'role': 'assistant', 'content': 'not a turtle.'},
            {
                'role': 'user',
                'content': (
                    'Question: What is Priya doing right now?\nAnswer: '
                    + 'Priya is currently '
                ),
            },
            {'role': 'assistant', 'content': 'sleeping.'},
            {'role': 'user', 'content': augmented_prompt},
            {'role': 'assistant', 'content': response},
        ]
        result = self._client.chat.completions.create(
            model=self._model_name,
            messages=messages,
            max_tokens=1,
            seed=None,
            logprobs=1,
            stream=False,
            echo=True,
        )
      except (together.error.RateLimitError,
              together.error.APIError,
              together.error.ServiceUnavailableError,
              together.error.InvalidRequestError) as err:
        if attempts >= _NUM_SILENT_ATTEMPTS:
          print(f'  Exception: {err}')
          print(f'  Choice exception prompt: {augmented_prompt}')
        if isinstance(err, together.error.APIError) or isinstance(
            err, together.error.InvalidRequestError
        ):
          # If hit the error that arises from a prompt that is too long then
          # re-run the trimming function with a more pessimistic guess of the
          # the number of characters per token.
          augmented_prompt = _ensure_prompt_not_too_long(
              original_prompt, 1, guess_chars_per_token=1
          )
        continue
      else:
        logprobs = result.prompt[0].logprobs
        response_idx = _find_response_start_index(logprobs.tokens)
        response_log_probs = logprobs.token_logprobs[response_idx:]
        score = sum(response_log_probs)
        return score

    raise language_model.InvalidResponseError(
        f'Failed to get logprobs after {attempts+1} attempts.\n Exception'
        f' prompt: {augmented_prompt}'
    )
Returns the log probability of the prompt and response.
concordia/language_model/together_ai.py