def __init__()

in sdk/python/generative-ai/rag/code_first/flows/chat-with-index/src/utils/oai.py [0:0]


    def __init__(self):
        if os.getenv("OPENAI_API_TYPE") is not None:
            openai.api_type = os.getenv("OPENAI_API_TYPE")
        if os.getenv("OPENAI_API_BASE") is not None:
            openai.api_base = os.environ.get("OPENAI_API_BASE")
        if os.getenv("OPENAI_API_VERSION") is not None:
            openai.api_version = os.environ.get("OPENAI_API_VERSION")
        if os.getenv("OPENAI_ORG_ID") is not None:
            openai.organization = os.environ.get("OPENAI_ORG_ID")
        if os.getenv("OPENAI_API_KEY") is None:
            raise ValueError("OPENAI_API_KEY is not set in environment variables")

        openai.api_key = os.environ.get("OPENAI_API_KEY")

        # A few sanity checks
        if openai.api_type == "azure" and openai.api_base is None:
            raise ValueError(
                "OPENAI_API_BASE is not set in environment variables, this is required when api_type==azure"
            )
        if openai.api_type == "azure" and openai.api_version is None:
            raise ValueError(
                "OPENAI_API_VERSION is not set in environment variables, this is required when api_type==azure"
            )
        if openai.api_type == "azure" and openai.api_key.startswith("sk-"):
            raise ValueError(
                "OPENAI_API_KEY should not start with sk- when api_type==azure, are you using openai key by mistake?"
            )