def _get_response_with_messages(self, messages: List[dict], **llm_config) -> ChatCompletion:
        """Get response from OpenAI chat completion API with retry mechanism.

        Args:
            messages (List[dict]): The messages to send to OpenAI chat completion API.
            **llm_config: Additional configuration for the chat completion API.

        Returns:
            ChatCompletion: The response from OpenAI API.
        """
        response: ChatCompletion = None
        num_attempt: int = 0

        while num_attempt < self._max_attempt:
            try:
                response = self._client.chat.completions.create(messages=messages, **llm_config)
                break
            except openai.RateLimitError as e:
                self.warning("  Failed due to RateLimitError...")
                wait_time = parse_wait_time_from_error(e)
                self._wait(num_attempt, wait_time=wait_time)
                self.warning("  Retrying...")
            except openai.BadRequestError as e:
                self.warning(f"  Failed due to Exception: {e}")
                self.warning("  Skip this request...")
                break
            except Exception as e:
                self.warning(f"  Failed due to Exception: {e}")
                num_attempt += 1
                self._wait(num_attempt)
                self.warning("  Retrying...")

        return response
Get response from OpenAI chat completion API with retry mechanism.

        Args:
            messages (List[dict]): The messages to send to OpenAI chat completion API.
            **llm_config: Additional configuration for the chat completion API.

        Returns:
            ChatCompletion: The response from OpenAI API.
        
pikerag/llm_client/standard_openai_api.py