def _get_content_from_response(self, response: ChatCompletion, messages: List[dict] = None) -> str:
        """Extract content from OpenAI chat completion response.

        Args:
            response (ChatCompletion): The response from OpenAI chat completion API.
            messages (List[dict], optional): The original messages sent to API. Defaults to None.

        Returns:
            str: The extracted content or empty string if extraction failed.
        """
        try:
            content = response.choices[0].message.content
            if content is None:
                finish_reason = response.choices[0].finish_reason
                warning_message = f"Non-Content returned due to {finish_reason}"

                if "content_filter" in finish_reason:
                    for reason, res_dict in response.choices[0].content_filter_results.items():
                        if res_dict["filtered"] is True or res_dict["severity"] != "safe":
                            warning_message += f", '{reason}': {res_dict}"

                self.warning(warning_message)
                self.debug(f"  -- Complete response: {response}")
                if messages is not None and len(messages) >= 1:
                    self.debug(f"  -- Last message: {messages[-1]}")

                content = ""
        except Exception as e:
            self.warning(f"Try to get content from response but get exception:\n  {e}")
            self.debug(
                f"  Response: {response}\n"
                f"  Last message: {messages}"
            )
            content = ""

        return content
Extract content from OpenAI chat completion response.

        Args:
            response (ChatCompletion): The response from OpenAI chat completion API.
            messages (List[dict], optional): The original messages sent to API. Defaults to None.

        Returns:
            str: The extracted content or empty string if extraction failed.
        
pikerag/llm_client/standard_openai_api.py