def validate_environment(cls, values: Dict) -> Dict:
        """Validate that api key and python package exists in environment."""
        openai_api_key = os.environ["OPENAI_API_KEY"]
        openai_api_type = os.environ.get("OPENAI_API_TYPE", "open_ai")
        openai_api_base = os.environ.get("OPENAI_API_BASE", None)
        try:
            import openai

        except ImportError:
            raise ValueError(
                "Could not import openai python package. "
                "Please install it with `pip install openai`."
            )
        values["api_key"] = openai.api_key = openai_api_key
        values["api_type"] = openai.api_type = openai_api_type
        if openai_api_base:
            values["api_base"] = openai.api_base = openai_api_base
        if openai_api_type == "azure":
            values["azure_api_version"] = openai.api_version = os.environ.get("OPENAI_API_VERSION", "2023-05-15")
        try:
            values["client"] = openai.ChatCompletion
        except AttributeError:
            raise ValueError(
                "`openai` has no `ChatCompletion` attribute, this is likely "
                "due to an old version of the openai package. Try upgrading it "
                "with `pip install --upgrade openai`."
            )
        # if values["n"] < 1:
        #     raise ValueError("n must be at least 1.")
        # if values["n"] > 1 and values["streaming"]:
        #     raise ValueError("n must be 1 when streaming.")
        return values
Validate that api key and python package exists in environment.
autochain/models/chat_openai.py