AzureML Chat Online Endpoint
AzureML 是一个用于构建、训练和部署机器学习模型的平台。用户可以在模型目录中探索要部署的模型类型,该目录提供了 Azure 基础模型和 OpenAI 模型。Azure 基础模型包括各种开源模型和流行的 Hugging Face 模型。用户还可以将自己喜欢的模型导入到 AzureML 中。
本笔记本介绍了如何使用托管在 AzureML 在线端点
上的聊天模型。
from langchain.chat_models.azureml_endpoint import AzureMLChatOnlineEndpoint
设置
要使用这个包装器,您必须在 AzureML 上部署一个模型并获取以下参数:
endpoint_api_key
:端点提供的 API 密钥endpoint_url
:端点提供的 REST 端点 URL
内容格式化器
content_formatter
参数是一个处理类,用于将 AzureML 端点的请求和响应转换为所需的模式。由于模型目录中有各种各样的模型,每个模型可能会以不同的方式处理数据,因此提供了一个 ContentFormatterBase
类,允许用户按照自己的喜好转换数据。提供了以下内容格式化器:
LLamaContentFormatter
:为 LLaMa2-chat 格式化请求和响应数据
from langchain.chat_models.azureml_endpoint import LlamaContentFormatter
from langchain.schema import HumanMessage
chat = AzureMLChatOnlineEndpoint(content_formatter=LlamaContentFormatter())
response = chat(messages=[
HumanMessage(content="Will the Collatz conjecture ever be solved?")
])
response
AIMessage(content=' The Collatz Conjecture is one of the most famous unsolved problems in mathematics, and it has been the subject of much study and research for many years. While it is impossible to predict with certainty whether the conjecture will ever be solved, there are several reasons why it is considered a challenging and important problem:\n\n1. Simple yet elusive: The Collatz Conjecture is a deceptively simple statement that has proven to be extraordinarily difficult to prove or disprove. Despite its simplicity, the conjecture has eluded some of the brightest minds in mathematics, and it remains one of the most famous open problems in the field.\n2. Wide-ranging implications: The Collatz Conjecture has far-reaching implications for many areas of mathematics, including number theory, algebra, and analysis. A solution to the conjecture could have significant impacts on these fields and potentially lead to new insights and discoveries.\n3. Computational evidence: While the conjecture remains unproven, extensive computational evidence supports its validity. In fact, no counterexample to the conjecture has been found for any starting value up to 2^64 (a number', additional_kwargs={}, example=False)