Home / Class/ AzureChatOpenAI Class — langchain Architecture

AzureChatOpenAI Class — langchain Architecture

Architecture documentation for the AzureChatOpenAI class in azure.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  f4fba558_cc0c_889d_7300_357dd6319410["AzureChatOpenAI"]
  6acbd332_f387_0c7a_34ab_a3d88a1064cb["BaseChatOpenAI"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|extends| 6acbd332_f387_0c7a_34ab_a3d88a1064cb
  999f3bf7_7a88_4ff2_5fab_c8a83e267ce7["azure.py"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|defined in| 999f3bf7_7a88_4ff2_5fab_c8a83e267ce7
  736af96d_e3b9_039b_a2a6_5ee64d6f5100["get_lc_namespace()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| 736af96d_e3b9_039b_a2a6_5ee64d6f5100
  fdad87bb_2b15_4565_7cf1_104aa70f0509["lc_secrets()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| fdad87bb_2b15_4565_7cf1_104aa70f0509
  9b178bed_eab4_7ca8_f1b5_0d0290130c6b["is_lc_serializable()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| 9b178bed_eab4_7ca8_f1b5_0d0290130c6b
  058f181f_b6b2_c2f5_78fa_ac49bd19b23d["validate_environment()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| 058f181f_b6b2_c2f5_78fa_ac49bd19b23d
  c05287c0_1fc6_ae7c_de06_248314f384a1["_set_model_profile()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| c05287c0_1fc6_ae7c_de06_248314f384a1
  a573c0c0_7823_e9b1_aca6_2adcedc9f007["_identifying_params()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| a573c0c0_7823_e9b1_aca6_2adcedc9f007
  4d5ec30d_8b1a_ce81_af3e_c5f897943e8a["_llm_type()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| 4d5ec30d_8b1a_ce81_af3e_c5f897943e8a
  71a85e6f_41cc_b5d1_8aeb_3031c811da56["lc_attributes()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| 71a85e6f_41cc_b5d1_8aeb_3031c811da56
  dcc9d72a_2af5_fead_7eaa_c3cecdf1a7de["_default_params()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| dcc9d72a_2af5_fead_7eaa_c3cecdf1a7de
  4cce1487_db33_327e_59f9_e548f29e2eab["_get_ls_params()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| 4cce1487_db33_327e_59f9_e548f29e2eab
  3b009c25_037f_11a6_ec01_323e19f38821["_create_chat_result()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| 3b009c25_037f_11a6_ec01_323e19f38821
  8e2c4abf_ca45_d753_978f_0d691f5b6047["_get_request_payload()"]
  f4fba558_cc0c_889d_7300_357dd6319410 -->|method| 8e2c4abf_ca45_d753_978f_0d691f5b6047

Relationship Graph

Source Code

libs/partners/openai/langchain_openai/chat_models/azure.py lines 34–1164

class AzureChatOpenAI(BaseChatOpenAI):
    r"""Azure OpenAI chat model integration.

    Setup:
        Head to the Azure [OpenAI quickstart guide](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/chatgpt-quickstart?tabs=keyless%2Ctypescript-keyless%2Cpython-new%2Ccommand-line&pivots=programming-language-python)
        to create your Azure OpenAI deployment.

        Then install `langchain-openai` and set environment variables
        `AZURE_OPENAI_API_KEY` and `AZURE_OPENAI_ENDPOINT`:

        ```bash
        pip install -U langchain-openai

        export AZURE_OPENAI_API_KEY="your-api-key"
        export AZURE_OPENAI_ENDPOINT="https://your-endpoint.openai.azure.com/"
        ```

    Key init args — completion params:
        azure_deployment:
            Name of Azure OpenAI deployment to use.
        temperature:
            Sampling temperature.
        max_tokens:
            Max number of tokens to generate.
        logprobs:
            Whether to return logprobs.

    Key init args — client params:
        api_version:
            Azure OpenAI REST API version to use (distinct from the version of the
            underlying model). [See more on the different versions.](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning)
        timeout:
            Timeout for requests.
        max_retries:
            Max number of retries.
        organization:
            OpenAI organization ID. If not passed in will be read from env
            var `OPENAI_ORG_ID`.
        model:
            The name of the underlying OpenAI model. Used for tracing and token
            counting. Does not affect completion. E.g. `'gpt-4'`, `'gpt-35-turbo'`, etc.
        model_version:
            The version of the underlying OpenAI model. Used for tracing and token
            counting. Does not affect completion. E.g., `'0125'`, `'0125-preview'`, etc.

    See full list of supported init args and their descriptions in the params section.

    Instantiate:
        ```python
        from langchain_openai import AzureChatOpenAI

        model = AzureChatOpenAI(
            azure_deployment="your-deployment",
            api_version="2024-05-01-preview",
            temperature=0,
            max_tokens=None,
            timeout=None,
            max_retries=2,
            # organization="...",
            # model="gpt-35-turbo",
            # model_version="0125",
            # other params...
        )
        ```

    !!! note
        Any param which is not explicitly supported will be passed directly to the
        `openai.AzureOpenAI.chat.completions.create(...)` API every time to the model is
        invoked.

        For example:

        ```python
        from langchain_openai import AzureChatOpenAI
        import openai

        AzureChatOpenAI(..., logprobs=True).invoke(...)

        # results in underlying API call of:

        openai.AzureOpenAI(..).chat.completions.create(..., logprobs=True)

Extends

Frequently Asked Questions

What is the AzureChatOpenAI class?
AzureChatOpenAI is a class in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/azure.py.
Where is AzureChatOpenAI defined?
AzureChatOpenAI is defined in libs/partners/openai/langchain_openai/chat_models/azure.py at line 34.
What does AzureChatOpenAI extend?
AzureChatOpenAI extends BaseChatOpenAI.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free