Azure AI
所有與 Azure AI Foundry 及其相關專案相關的功能。
Azure AI、Dynamic Sessions、SQL Server 的整合套件維護在 langchain-azure 儲存庫中。
聊天模型
我們建議開發人員從 (langchain-azure-ai
) 開始,以存取 Azure AI Foundry 中提供的所有模型。
Azure AI Chat Completions Model
使用 AzureAIChatCompletionsModel
類別存取如 Azure OpenAI、DeepSeek R1、Cohere、Phi 和 Mistral 等模型。
pip install -U langchain-azure-ai
設定您的 API 金鑰和端點。
export AZURE_INFERENCE_CREDENTIAL=your-api-key
export AZURE_INFERENCE_ENDPOINT=your-endpoint
from langchain_azure_ai.chat_models import AzureAIChatCompletionsModel
llm = AzureAIChatCompletionsModel(
model_name="gpt-4o",
api_version="2024-05-01-preview",
)
llm.invoke('Tell me a joke and include some emojis')
API 參考:AzureAIChatCompletionsModel
嵌入模型
Azure AI 模型嵌入推論
pip install -U langchain-azure-ai
設定您的 API 金鑰和端點。
export AZURE_INFERENCE_CREDENTIAL=your-api-key
export AZURE_INFERENCE_ENDPOINT=your-endpoint
from langchain_azure_ai.embeddings import AzureAIEmbeddingsModel
embed_model = AzureAIEmbeddingsModel(
model_name="text-embedding-ada-002"
)
API 參考:AzureAIEmbeddingsModel