이 문서는 AzureAIChatCompletionsModel chat models 시작하는 데 도움을 드립니다. 모든 AzureAIChatCompletionsModel 기능 및 구성에 대한 자세한 문서는 API reference를 참조하세요. AzureAIChatCompletionsModel 클래스는 Azure AI Foundry SDK를 사용합니다. AI Foundry는 AzureOpenAI, Cohere, Llama, Phi-3/4, DeepSeek-R1 등 여러 chat model을 제공합니다. 최신 모델과 비용, context window, 지원되는 입력 유형에 대한 정보는 Azure docs에서 확인할 수 있습니다.

Overview

Integration details

ClassPackageLocalSerializableJS supportDownloadsVersion
AzureAIChatCompletionsModellangchain-azure-aiPyPI - DownloadsPyPI - Version

Model features

Tool callingStructured outputJSON modeImage inputAudio inputVideo inputToken-level streamingNative asyncToken usageLogprobs

Setup

AzureAIChatCompletionsModel 모델에 액세스하려면 Azure account를 생성하고, API key를 받고, langchain-azure-ai integration package를 설치해야 합니다.

Credentials

배포를 생성하고 API key를 생성하는 방법은 Azure docs를 참조하세요. 모델이 배포되면 AI Foundry에서 ‘get endpoint’ 버튼을 클릭합니다. 그러면 endpoint와 api key가 표시됩니다. 이 작업을 완료한 후 AZURE_AI_CREDENTIAL 및 AZURE_AI_ENDPOINT 환경 변수를 설정하세요:
import getpass
import os

if not os.getenv("AZURE_AI_CREDENTIAL"):
    os.environ["AZURE_AI_CREDENTIAL"] = getpass.getpass(
        "Enter your AzureAIChatCompletionsModel API key: "
    )

if not os.getenv("AZURE_AI_ENDPOINT"):
    os.environ["AZURE_AI_ENDPOINT"] = getpass.getpass(
        "Enter your model endpoint: "
    )
모델 호출에 대한 자동 추적을 원하시면 아래 주석을 해제하여 LangSmith API key를 설정할 수도 있습니다:
os.environ["LANGSMITH_TRACING"] = "true"
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")

Installation

LangChain AzureAIChatCompletionsModel integration은 langchain-azure-ai package에 있습니다:
pip install -qU langchain-azure-ai

Instantiation

이제 model 객체를 인스턴스화하고 chat completion을 생성할 수 있습니다:
from langchain_azure_ai.chat_models import AzureAIChatCompletionsModel

llm = AzureAIChatCompletionsModel(
    model_name="gpt-4",
    temperature=0,
    max_tokens=None,
    timeout=None,
    max_retries=2,
)

Invocation

messages = [
    (
        "system",
        "You are a helpful assistant that translates English to French. Translate the user sentence.",
    ),
    ("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msg
AIMessage(content="J'adore programmer.", additional_kwargs={}, response_metadata={'model': 'gpt-4o-2024-05-13', 'token_usage': {'input_tokens': 31, 'output_tokens': 4, 'total_tokens': 35}, 'finish_reason': 'stop'}, id='run-c082dffd-b1de-4b3f-943f-863836663ddb-0', usage_metadata={'input_tokens': 31, 'output_tokens': 4, 'total_tokens': 35})
print(ai_msg.content)
J'adore programmer.

API reference

모든 AzureAIChatCompletionsModel 기능 및 구성에 대한 자세한 문서는 API reference를 참조하세요: python.langchain.com/api_reference/azure_ai/chat_models/langchain_azure_ai.chat_models.AzureAIChatCompletionsModel.html
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I