Skip to main content
所有与 Microsoft Azure 以及其他 Microsoft 产品集成的 LangChain。

聊天模型

Microsoft通过Azure提供三种主要方式访问聊天模型:
  1. Azure OpenAI - 通过微软Azure安全的企业平台,提供访问OpenAI强大模型(如o3、4.1以及其他模型)的权限。
  2. Azure AI - 通过统一的API,提供访问来自不同提供商(包括Anthropic、DeepSeek、Cohere、Phi和Mistral)的各种模型的权限。
  3. Azure ML - 允许使用Azure机器学习部署和管理您自己的定制模型或微调后的开源模型。

Azure OpenAI

微软Azure,通常被称为 Azure,是由 Microsoft 运营的云计算平台,通过全球数据中心提供应用程序和服务的访问、管理和开发。它提供包括软件即服务(SaaS)、平台即服务(PaaS)和基础设施即服务(IaaS)在内的多种功能。Microsoft Azure 支持许多编程语言、工具和框架,包括微软特定的和第三方软件及系统。
Azure OpenAI 是一项 Azure 服务,提供来自 OpenAI 的强大语言模型,包括 GPT-3Codex 和嵌入模型系列,用于内容生成、摘要、语义搜索以及自然语言到代码的翻译。
pip install langchain-openai
设置环境变量以访问 Azure OpenAI 服务。
import os

os.environ["AZURE_OPENAI_ENDPOINT"] = "https://<your-endpoint.openai.azure.com/"
os.environ["AZURE_OPENAI_API_KEY"] = "your AzureOpenAI key"
查看使用示例
from langchain_openai import AzureChatOpenAI

Azure AI

Azure AI Foundry 通过 AzureAIChatCompletionsModel 类提供对来自 Azure OpenAI、DeepSeek R1、Cohere、Phi 和 Mistral 等各种提供商的广泛模型的访问。
pip install -U langchain-azure-ai
配置您的API密钥和端点。
export AZURE_AI_CREDENTIAL=your-api-key
export AZURE_AI_ENDPOINT=your-endpoint
from langchain_azure_ai.chat_models import AzureAIChatCompletionsModel

llm = AzureAIChatCompletionsModel(
    model_name="gpt-4o",
    api_version="2024-05-01-preview",
)
查看使用示例

Azure ML 在线端点

查看此处的文档以访问托管在Azure Machine Learning上的聊天模型。

大型语言模型

Azure ML

查看使用示例
from langchain_community.llms.azureml_endpoint import AzureMLOnlineEndpoint

Azure OpenAI

查看使用示例
from langchain_openai import AzureOpenAI

嵌入式模型

Microsoft通过Azure提供两种主要方式访问嵌入模型:

Azure OpenAI

查看使用示例
from langchain_openai import AzureOpenAIEmbeddings

Azure AI

pip install -U langchain-azure-ai
配置您的API密钥和端点。
export AZURE_AI_CREDENTIAL=your-api-key
export AZURE_AI_ENDPOINT=your-endpoint
from langchain_azure_ai.embeddings import AzureAIEmbeddingsModel

embed_model = AzureAIEmbeddingsModel(
    model_name="text-embedding-ada-002"
)

文档加载器

Azure AI 数据

[Azure AI Foundry(原名 Azure AI Studio)(https://ai.azure.com/) 提供了将数据资产上传到云存储以及从以下来源注册现有数据资产的功能:
  • Microsoft OneLake
  • Azure Blob Storage
  • Azure Data Lake gen 2
首先,您需要安装几个Python包。
pip install azureml-fsspec, azure-ai-generative
查看使用示例
from langchain.document_loaders import AzureAIDataLoader

Azure AI 文档智能

Azure AI 文档智能分析(之前称为 Azure Form Recognizer)是一种基于机器学习的服务,可以从数字或扫描的PDF、图片、Office和HTML文件中提取文本(包括手写文本)、表格、文档结构和键值对。
文档智能分析支持 PDFJPEG/JPGPNGBMPTIFFHEIFDOCXXLSXPPTXHTML 首先,您需要安装一个Python包。
pip install azure-ai-documentintelligence
查看使用示例
from langchain.document_loaders import AzureAIDocumentIntelligenceLoader

Azure Blob 存储

Azure Blob Storage 是微软的云对象存储解决方案。Blob Storage 优化用于存储大量非结构化数据。非结构化数据是指不符合特定数据模型或定义的数据,例如文本或二进制数据。
Azure Blob Storage 的设计用途包括:
  • 直接将图像或文档发送到浏览器。
  • 存储文件以实现分布式访问。
  • 流式传输视频和音频。
  • 写入日志文件。
  • 存储数据以备备份和恢复、灾难恢复和归档。
  • 存储数据供本地或Azure托管的服务进行分析。
pip install langchain-azure-storage
查看Azure Blob存储加载器的使用示例
from langchain_azure_storage.document_loaders import AzureBlobStorageLoader

微软OneDrive

微软 OneDrive(原名 SkyDrive)是微软运营的文件托管服务。
首先,您需要安装一个Python包。
pip install o365
查看使用示例
from langchain_community.document_loaders import OneDriveLoader

微软OneDrive文件

微软 OneDrive(原名 SkyDrive)是微软运营的文件托管服务。
首先,您需要安装一个Python包。
pip install o365
from langchain_community.document_loaders import OneDriveFileLoader

微软Word

Microsoft Word 是由微软开发的文字处理软件。 查看使用示例
from langchain_community.document_loaders import UnstructuredWordDocumentLoader

微软Excel

Microsoft Excel 是由 Microsoft 开发的一款电子表格编辑器,适用于 Windows、macOS、Android、iOS 和 iPadOS。 它具备计算或计算能力、绘图工具、数据透视表以及名为 Visual Basic for Applications (VBA) 的宏编程语言。Excel 是 Microsoft 365 软件套件的一部分。
UnstructuredExcelLoader 用于加载 Microsoft Excel 文件。加载器与 .xlsx.xls 文件兼容。 页面内容将是 Excel 文件的原始文本。如果您以 "elements" 模式使用加载器,Excel 文件的 HTML 表示形式将在文档元数据中的 text_as_html 键下可用。 查看使用示例
from langchain_community.document_loaders import UnstructuredExcelLoader

微软 SharePoint

微软 SharePoint 是一个基于网站的协作系统 它使用工作流应用程序、“列表”数据库以及其他网页组件和安全功能, 由微软开发,以赋能商业团队共同工作。
查看使用示例
from langchain_community.document_loaders.sharepoint import SharePointLoader

微软 PowerPoint

微软 PowerPoint 是微软公司的一款演示文稿程序。
查看使用示例
from langchain_community.document_loaders import UnstructuredPowerPointLoader

微软 OneNote

首先,让我们安装依赖项:
pip install bs4 msal
查看使用示例
from langchain_community.document_loaders.onenote import OneNoteLoader

Playwright URL 加载器

Playwright 是由 Microsoft 开发的开源自动化工具, 它允许您通过编程方式控制并自动化网页浏览器。它旨在进行端到端测试、抓取以及自动化 跨各种网页浏览器(如 ChromiumFirefoxWebKit)的任务。 首先,让我们安装依赖项:
pip install playwright unstructured
查看使用示例
from langchain_community.document_loaders.onenote import OneNoteLoader

矢量存储

Azure Cosmos DB

AI智能体可以依赖Azure Cosmos DB作为统一的记忆系统解决方案,享受速度、可扩展性和简单性。这项服务成功启用了OpenAI的ChatGPT服务,以高可靠性和低维护成本动态扩展。由原子记录序列引擎驱动,它是世界上第一个提供无服务器模式的全球分布式NoSQL关系型向量数据库服务。 以下是两个可用的 Azure Cosmos DB API,它们可以提供向量存储功能。

Azure Cosmos DB for MongoDB (vCore)

Azure Cosmos DB for MongoDB vCore 可以轻松创建一个具有完整原生 MongoDB 支持的数据库。 您可以通过将应用程序指向 MongoDB vCore 账户的连接字符串 API,应用您的 MongoDB 经验并继续使用您喜欢的 MongoDB 驱动程序、SDK 和工具。 使用 Azure Cosmos DB for MongoDB vCore 中的向量搜索,可以无缝地将您的基于 AI 的应用程序与存储在 Azure Cosmos DB 中的数据进行集成。
安装和设置
查看详细配置说明 我们需要安装 pymongo Python 包。
pip install pymongo
在Microsoft Azure上部署Azure Cosmos DB
Azure Cosmos DB for MongoDB vCore 为开发者提供了一款完全托管的、兼容 MongoDB 的数据库服务,用于构建具有熟悉架构的现代应用程序。 使用MongoDB vCore版本的Cosmos DB,开发人员可以在迁移现有应用程序或构建新应用程序时,享受到原生Azure集成、低总拥有成本(TCO)以及熟悉的vCore架构带来的好处。 免费注册,今天开始使用。 查看使用示例
from langchain_community.vectorstores import AzureCosmosDBVectorSearch

Azure Cosmos DB NoSQL

Azure Cosmos DB for NoSQL 现已提供预览版的向量索引和搜索功能。 该功能旨在处理高维向量,实现任何规模下的高效和精确向量搜索。您现在可以直接在文档中存储向量,与您的数据并存。这意味着您数据库中的每个文档不仅可以包含传统的无模式数据,还可以包含作为文档其他属性的高维向量。这种数据和向量的同位存储允许进行高效的索引和搜索,因为向量存储在与它们所代表的数据相同的逻辑单元中。这简化了数据管理、AI 应用架构以及基于向量的操作效率。
安装和设置
查看详细配置说明 我们需要安装 azure-cosmos Python 包。
pip install azure-cosmos
在Microsoft Azure上部署Azure Cosmos DB
Azure Cosmos DB通过提供动态和弹性自动扩展的极高响应性,为现代应用程序和智能工作负载提供解决方案。它可在每个Azure区域使用,并能够自动将数据复制到更靠近用户的位置。它提供有SLA保证的低延迟和高可用性。 免费注册,今天开始使用。 查看使用示例
from langchain_community.vectorstores import AzureCosmosDBNoSQLVectorSearch

Azure PostgreSQL数据库

Azure Database for PostgreSQL - Flexible Server 是基于开源的Postgres数据库引擎的关系型数据库服务。它是一个完全托管的数据库即服务,能够以可预测的性能、安全性、高可用性和动态可伸缩性处理关键任务工作负载。 查看 Azure Database for PostgreSQL 设置说明 只需使用您的 Azure Portal 中的 连接字符串 由于 Azure Database for PostgreSQL 是开源的 Postgres,您可以使用 LangChain 的 Postgres 支持 来连接到 Azure Database for PostgreSQL。

Azure SQL 数据库

Azure SQL 数据库 是一种强大的服务,结合了可扩展性、安全性和高可用性,提供现代数据库解决方案的所有优势。它还提供专门的向量数据类型和内置函数,简化了在关系数据库中直接存储和查询向量嵌入的过程。这消除了对单独的向量数据库和相关集成的需求,提高了解决方案的安全性,同时降低了整体复杂性。 通过利用您当前的SQL Server数据库进行向量搜索,您可以在最小化开支的同时提升数据处理能力,并避免过渡到新系统的挑战。
安装和设置
查看详细配置说明 我们需要安装 langchain-sqlserver python 包。
!pip install langchain-sqlserver==0.1.1
在Microsoft Azure上部署Azure SQL数据库
免费注册,今天开始使用。 查看使用示例
from langchain_sqlserver import SQLServer_VectorStore

Azure AI 搜索

Azure AI Search 是一种云搜索服务,为开发者提供基础设施、API 和工具,以实现大规模的向量、关键词和混合查询的信息检索。请参阅此处了解使用示例。
from langchain_community.vectorstores.azuresearch import AzureSearch

检索器

Azure AI 搜索

Azure AI Search(之前称为 Azure SearchAzure Cognitive Search)是一种云搜索服务,为开发者提供基础设施、API和工具,以在Web、移动和企业应用程序中的私有、异构内容上构建丰富的搜索体验。
搜索是任何向用户展示文本的应用程序的基础,常见场景包括目录或文档搜索、在线零售应用程序或对专有内容的探索。当您创建搜索服务时,您将使用以下功能:
  • 一个用于在包含用户拥有内容的搜索索引上进行全文搜索的搜索引擎
  • 丰富的索引,包括词汇分析和可选的AI增强内容提取和转换
  • 丰富的查询语法,支持文本搜索、模糊搜索、自动完成、地理搜索等
  • 通过REST API和Azure SDK客户端库进行编程
  • 在数据层、机器学习层和AI(AI服务)中集成Azure
查看设置说明 查看使用示例
from langchain_community.retrievers import AzureAISearchRetriever

向量存储

Azure Database for PostgreSQL

Azure Database for PostgreSQL - Flexible Server 是基于开源 Postgres 数据库引擎的关系型数据库服务。它是一个完全托管的数据库即服务,能够以可预测的性能、安全性、高可用性和动态可伸缩性处理关键任务工作负载。
查看 Azure Database for PostgreSQL 设置说明 您需要在您的数据库中启用 pgvector 扩展 才能将 Postgres 用作向量存储。一旦启用了扩展,您就可以使用 LangChain 中的 PGVector 连接到 Azure Database for PostgreSQL。 查看使用示例。只需使用您的Azure Portal中的连接字符串即可。

工具

Azure 容器应用动态会话

我们需要从 Azure Container Apps 服务中获取 POOL_MANAGEMENT_ENDPOINT 环境变量。 请参阅此处的说明。 我们需要安装一个Python包。
pip install langchain-azure-dynamic-sessions
查看使用示例
from langchain_azure_dynamic_sessions import SessionsPythonREPLTool

必应搜索

遵循此处的文档以获取此工具的详细说明和指导。 环境变量 BING_SUBSCRIPTION_KEYBING_SEARCH_URL 来自 Bing 搜索资源是必需的。
from langchain_community.tools.bing_search import BingSearchResults
from langchain_community.utilities import BingSearchAPIWrapper

api_wrapper = BingSearchAPIWrapper()
tool = BingSearchResults(api_wrapper=api_wrapper)

工具包

Azure 人工智能服务

我们需要安装几个 Python 包。
pip install azure-ai-formrecognizer azure-cognitiveservices-speech azure-ai-vision-imageanalysis
查看使用示例
from langchain_community.agent_toolkits import azure_ai_services

Azure AI 服务单独工具

The azure_ai_services 工具包包括以下工具:

Azure认知服务

我们需要安装几个 Python 包。
pip install azure-ai-formrecognizer azure-cognitiveservices-speech azure-ai-vision-imageanalysis
查看使用示例
from langchain_community.agent_toolkits import AzureCognitiveServicesToolkit

Azure AI 服务单独工具

azure_ai_services 工具包包括查询 Azure Cognitive Services 的工具:
  • AzureCogsFormRecognizerTool:表单识别 API
  • AzureCogsImageAnalysisTool:图像分析 API
  • AzureCogsSpeech2TextTool:语音转文本 API
  • AzureCogsText2SpeechTool:文本转语音 API
  • AzureCogsTextAnalyticsHealthTool:健康文本分析 API
from langchain_community.tools.azure_cognitive_services import (
    AzureCogsFormRecognizerTool,
    AzureCogsImageAnalysisTool,
    AzureCogsSpeech2TextTool,
    AzureCogsText2SpeechTool,
    AzureCogsTextAnalyticsHealthTool,
)

微软Office 365电子邮件和日历

我们需要安装 O365 Python 包。
pip install O365
查看使用示例
from langchain_community.agent_toolkits import O365Toolkit

Office 365 单个工具

您可以使用Office 365工具包中的单个工具:
  • O365CreateDraftMessage:在Office 365中创建草稿邮件
  • O365SearchEmails:在Office 365中搜索邮件消息
  • O365SearchEvents:在Office 365中搜索日历事件
  • O365SendEvent:在Office 365中发送日历事件
  • O365SendMessage:在Office 365中发送邮件
from langchain_community.tools.office365 import O365CreateDraftMessage
from langchain_community.tools.office365 import O365SearchEmails
from langchain_community.tools.office365 import O365SearchEvents
from langchain_community.tools.office365 import O365SendEvent
from langchain_community.tools.office365 import O365SendMessage

微软Azure PowerBI

我们需要安装 azure-identity Python 包。
pip install azure-identity
查看使用示例
from langchain_community.agent_toolkits import PowerBIToolkit
from langchain_community.utilities.powerbi import PowerBIDataset

PowerBI 单个工具

您可以使用 Azure PowerBI Toolkit 中的单个工具:
  • InfoPowerBITool:获取 PowerBI 数据集的元数据
  • ListPowerBITool:获取表名
  • QueryPowerBITool:查询 PowerBI 数据集
from langchain_community.tools.powerbi.tool import InfoPowerBITool
from langchain_community.tools.powerbi.tool import ListPowerBITool
from langchain_community.tools.powerbi.tool import QueryPowerBITool

PlayWright 浏览器工具包

Playwright 是由 Microsoft 开发的开源自动化工具, 它允许您通过编程方式控制并自动化网页浏览器。它旨在进行端到端测试、抓取以及自动化各种网页浏览器(如 ChromiumFirefoxWebKit)的任务。 我们需要安装几个 Python 包。
pip install playwright lxml
查看使用示例
from langchain_community.agent_toolkits import PlayWrightBrowserToolkit

PlayWright 浏览器独立工具

您可以使用 PlayWright 浏览器工具包中的单个工具。
from langchain_community.tools.playwright import ClickTool
from langchain_community.tools.playwright import CurrentWebPageTool
from langchain_community.tools.playwright import ExtractHyperlinksTool
from langchain_community.tools.playwright import ExtractTextTool
from langchain_community.tools.playwright import GetElementsTool
from langchain_community.tools.playwright import NavigateTool
from langchain_community.tools.playwright import NavigateBackTool

Azure Cosmos DB for Apache Gremlin

我们需要安装一个Python包。
pip install gremlinpython
查看使用示例
from langchain_community.graphs import GremlinGraph
from langchain_community.graphs.graph_document import GraphDocument, Node, Relationship

工具

必应搜索API

微软必应,通常被称为 BingBing Search, 是由 Microsoft 所拥有和运营的网页搜索引擎。
查看使用示例
from langchain_community.utilities import BingSearchAPIWrapper

更多

微软Presidio

Presidio(源自拉丁语praesidium,意为“保护,驻军”) 有助于确保敏感数据得到适当的管理和治理。它为文本和图像中的私人实体提供快速识别和匿名化模块,例如信用卡号码、姓名、位置、社会保障号码、比特币钱包、美国电话号码、财务数据等。
首先,您需要安装几个Python包并下载一个SpaCy模型。
pip install langchain-experimental openai presidio-analyzer presidio-anonymizer spacy Faker
python -m spacy download en_core_web_lg
查看使用示例
from langchain_experimental.data_anonymizer import PresidioAnonymizer, PresidioReversibleAnonymizer