def METHOD_NAME(self, text: str, expected_completion_token_length: int = 0) -> str:
    """
    Truncates text from the right to fit within the context window given by `max_request_length`
    minus the expected completion length (defaults to 0).
    """
    # First truncate the text so it's within `CohereClient.TOKENIZE_MAX_TEXT_LENGTH` length.
    text = text[: CohereClient.TOKENIZE_API_MAX_TEXT_LENGTH]
    max_length: int = self.max_request_length - expected_completion_token_length
    result: str = self.decode(self.encode(text, truncation=True, max_length=max_length).tokens)
    # HACK: For the vast majority of cases, the above logic works, but it sometimes doesn't work
    # for non-English text, since Cohere technically only supports English at the moment.
    while not self.fits_within_context_window(result, expected_completion_token_length):
        result = result[:-1]
    return result