使用自己的数据在Azure聊天完成模型中(预览版)
注意:openai库有更新版本可用。请参阅 https://github.com/openai/openai-python/discussions/742
这个示例展示了如何在Azure OpenAI服务模型中使用自己的数据。该功能目前处于预览阶段。
在Azure上使用您的数据可以运行支持的聊天模型,如GPT-3.5-Turbo和GPT-4,而无需训练或微调模型。在您的数据上运行模型可以让您以更高的准确性和速度进行聊天和分析数据。Azure OpenAI在您的数据上的一个关键优势是它能够定制会话AI的内容。因为模型可以访问并引用特定来源来支持其响应,答案不仅基于其预训练知识,还基于指定数据源中可用的最新信息。这些基础数据还有助于模型避免基于过时或不正确信息生成响应。
Azure OpenAI在您自己的数据上与Azure认知搜索提供了一个可定制的、预构建的知识检索解决方案,可以构建一个会话AI应用程序。要查看知识检索和语义搜索的替代方法,请查看向量数据库的示例。
工作原理
Azure OpenAI on your own data 将模型与您的数据连接起来,使其能够检索和利用数据,从而增强模型的输出能力。与 Azure Cognitive Search 一起,根据用户输入和提供的对话历史,从指定的数据源中检索数据。然后,对数据进行增强处理,并重新提交给模型作为提示,为模型提供可以用来生成响应的上下文信息。
有关更多信息,请参阅Azure OpenAI 服务的数据、隐私和安全性。
先决条件
为了开始,我们将介绍一些先决条件。
要正确访问Azure OpenAI服务,我们需要在Azure门户上创建适当的资源(您可以在Microsoft Docs中查看如何执行此操作的详细指南)
要在Azure OpenAI模型中使用您自己的数据,您将需要:
- Azure OpenAI访问权限以及部署了聊天模型的资源(例如,GPT-3或GPT-4)
- Azure认知搜索资源
- Azure Blob存储资源
- 作为数据使用的文档(请参阅数据源选项)
要了解如何将您的文档上传到Blob存 储并使用Azure AI Studio创建索引的完整步骤,请参阅此快速入门指南。
设置
首先,我们安装必要的依赖项。
! pip install "openai>=0.28.1,<1.0.0"
! pip install python-dotenv
在这个示例中,我们将使用 dotenv
来加载我们的环境变量。为了连接到Azure
OpenAI和搜索索引,以下变量应该以 KEY=VALUE
的格式添加到一个名为 .env
的文件中:
OPENAI_API_BASE
- Azure OpenAI的终端节点。可以在Azure门户中的Azure OpenAI资源的“密钥和终结点”下找到。OPENAI_API_KEY
- Azure OpenAI的API密钥。可以在Azure门户中的Azure OpenAI资源的“密钥和终结点”下找到。如果使用Azure Active Directory身份验证,则可以省略(参见下面的“使用Microsoft Active Directory进行身份验证”)SEARCH_ENDPOINT
- Cognitive Search的终端节点。这个URL可以在Azure门户中的搜索资源的“概述”中找到。SEARCH_KEY
- Cognitive Search的API密钥。可以在Azure门户中的搜索资源的“密钥”下找到。SEARCH_INDEX_NAME
- 您使用自己的数据创建的索引的名称。
import os
import openai
import dotenv
dotenv.load_dotenv()
openai.api_base = os.environ["OPENAI_API_BASE"]
# Azure OpenAI 自定义数据功能仅在 2023-08-01-preview API 版本中提供支持。
openai.api_version = "2023-08-01-preview"
认证
Azure OpenAI 服务支持多种认证机制,包括 API 密钥和 Azure 凭据。
use_azure_active_directory = False # 将此标志设置为 True,如果您正在使用 Azure Active Directory。
使用API密钥进行身份验证
要设置OpenAI SDK以使用Azure
API密钥,我们需要将api_type
设置为azure
,并将api_key
设置为与您的端点关联的密钥(您可以在Azure门户的*“资源管理”下的“密钥和终结点”*中找到此密钥)。
if not use_azure_active_directory:
openai.api_type = 'azure'
openai.api_key = os.environ["OPENAI_API_KEY"]
使用Microsoft Active Directory进行身份验证
现在让我们看看如何通过Microsoft Active Directory身份验证获取密钥。有关如何设置此功能的更多信息,请参阅文档。
! pip install azure-identity
from azure.identity import DefaultAzureCredential
if use_azure_active_directory:
default_credential = DefaultAzureCredential()
token = default_credential.get_token("https://cognitiveservices.azure.com/.default")
openai.api_type = "azure_ad"
openai.api_key = token.token
令牌在一段时间内有效,之后将会过期。为了确保每个请求都发送一个有效的令牌,你可以通过连接到requests.auth来刷新一个即将过期的令牌:
import typing
import time
import requests
if typing.TYPE_CHECKING:
from azure.core.credentials import TokenCredential
class TokenRefresh(requests.auth.AuthBase):
def __init__(self, credential: "TokenCredential", scopes: typing.List[str]) -> None:
self.credential = credential
self.scopes = scopes
self.cached_token: typing.Optional[str] = None
def __call__(self, req):
if not self.cached_token or self.cached_token.expires_on - time.time() < 300:
self.cached_token = self.credential.get_token(*self.scopes)
req.headers["Authorization"] = f"Bearer {self.cached_token.token}"
return req
使用自己的数据完成聊天补全模型
设置上下文
在这个例子中,我们希望我们的模型基于Azure AI服务文档数据来生成回复。根据之前分享的快速入门,我们已经将markdown文件添加到了我们的搜索索引中,该文件是关于Azure AI服务和机器学习文档页面的内容。现在模型已经准备好回答关于Azure AI服务和机器学习的问题了。
代码
要使用Python SDK与Azure OpenAI模型使用自己的数据进行聊天,我们首先必须设置代码以针对聊天完成扩展端点,该端点旨在与您自己的数据一起使用。为此,我们创建了一个便利函数,可以调用它来为库设置自定义适配器,该适配器将针对给定部署ID的扩展端点。
import requests
def setup_byod(deployment_id: str) -> None:
"""Sets up the OpenAI Python SDK to use your own data for the chat endpoint.
:param deployment_id: The deployment ID for the model to use with your own data.
To remove this configuration, simply set openai.requestssession to None.
"""
class BringYourOwnDataAdapter(requests.adapters.HTTPAdapter):
def send(self, request, **kwargs):
request.url = f"{openai.api_base}/openai/deployments/{deployment_id}/extensions/chat/completions?api-version={openai.api_version}"
return super().send(request, **kwargs)
session = requests.Session()
# 挂载一个自定义适配器,该适配器将对使用指定 `deployment_id` 的任何调用使用扩展端点。
session.mount(
prefix=f"{openai.api_base}/openai/deployments/{deployment_id}",
adapter=BringYourOwnDataAdapter()
)
if use_azure_active_directory:
session.auth = TokenRefresh(default_credential, ["https://cognitiveservices.azure.com/.default"])
openai.requestssession = session
现在我们可以调用便利函数,使用我们计划用于自己数据的模型来配置SDK。
setup_byod("gpt-4")
通过为dataSources
关键参数提供我们的搜索端点、密钥和索引名称,现在对模型提出的任何问题都将基于我们自己的数据。另外,将提供一个名为context
的属性,用于显示模型用来回答问题所参考的数据。
completion = openai.ChatCompletion.create(
messages=[{"role": "user", "content": "What are the differences between Azure Machine Learning and Azure AI services?"}],
deployment_id="gpt-4",
dataSources=[ # 驼峰式命名法是故意为之,因为这是API所期望的格式。
{
"type": "AzureCognitiveSearch",
"parameters": {
"endpoint": os.environ["SEARCH_ENDPOINT"],
"key": os.environ["SEARCH_KEY"],
"indexName": os.environ["SEARCH_INDEX_NAME"],
}
}
]
)
print(completion)
{
"id": "65b485bb-b3c9-48da-8b6f-7d3a219f0b40",
"model": "gpt-4",
"created": 1693338769,
"object": "extensions.chat.completion",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "Azure AI services and Azure Machine Learning (AML) both aim to apply artificial intelligence (AI) to enhance business operations, but they target different audiences and offer different capabilities [doc1]. \n\nAzure AI services are designed for developers without machine learning experience and provide pre-trained models to solve general problems such as text analysis, image recognition, and natural language processing [doc5]. These services require general knowledge about your data without needing experience with machine learning or data science and provide REST APIs and language-based SDKs [doc2].\n\nOn the other hand, Azure Machine Learning is tailored for data scientists and involves a longer process of data collection, cleaning, transformation, algorithm selection, model training, and deployment [doc5]. It allows users to create custom solutions for highly specialized and specific problems, requiring familiarity with the subject matter, data, and expertise in data science [doc5].\n\nIn summary, Azure AI services offer pre-trained models for developers without machine learning experience, while Azure Machine Learning is designed for data scientists to create custom solutions for specific problems.",
"end_turn": true,
"context": {
"messages": [
{
"role": "tool",
"content": "{\"citations\": [{\"content\": \"<h2 id=\\\"how-are-azure-ai-services-and-azure-machine-learning-aml-similar\\\">How are Azure AI services and Azure Machine Learning (AML) similar?.</h2>\\n<p>Both have the end-goal of applying artificial intelligence (AI) to enhance business operations, though how each provides this in the respective offerings is different..</p>\\n<p>Generally, the audiences are different:</p>\\n<ul>\\n<li>Azure AI services are for developers without machine-learning experience..</li>\\n<li>Azure Machine Learning is tailored for data scientists.\", \"id\": null, \"title\": \"Azure AI services and machine learning\", \"filepath\": \"cognitive-services-and-machine-learning.md\", \"url\": \"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\", \"metadata\": {\"chunking\": \"orignal document size=1188. Scores=5.689296 and None.Org Highlight count=160.Filtering to chunk no. 2/Highlights=30 of size=137\"}, \"chunk_id\": \"2\"}, {\"content\": \"<td>Convert speech into text and text into natural-sounding speech..Translate from one language to another and enable speaker verification and recognition..</td>\\n</tr>\\n<tr>\\n<td><a href=\\\"https://azure.microsoft.com/services/cognitive-services/directory/vision/\\\">Vision</a></td>\\n<td>Recognize, identify, caption, index, and moderate your pictures, videos, and digital ink content..</td>\\n</tr>\\n<p></tbody>\\n</table></p>\\n<p>Use Azure AI services when you:</p>\\n<ul>\\n<li>Can use a generalized solution..</li>\\n</ul>\\n<p>Use other machine-learning solutions when you:</p>\\n<ul>\\n<li>Need to choose the algorithm and need to train on very specific data..</li>\\n</ul>\\n<h2 id=\\\"what-is-machine-learning\\\">What is machine learning?.</h2>\\n<p>Machine learning is a concept where you bring together data and an algorithm to solve a specific need..Once the data and algorithm are trained, the output is a model that you can use again with different data..The trained model provides insights based on the new data..</p>\\n<p>The process of building a machine learning system requires some knowledge of machine learning or data science..</p>\\n<p>Machine learning is provided using <a href=\\\"/azure/architecture/data-guide/technology-choices/data-science-and-machine-learning?.context=azure%2fmachine-learning%2fstudio%2fcontext%2fml-context\\\">Azure Machine Learning (AML) products and services</a>..</p>\\n<h2 id=\\\"what-is-an-azure-ai-service\\\">What is an Azure AI service?.</h2>\\n<p>An Azure AI service provides part or all of the components in a machine learning solution: data, algorithm, and trained model..These services are meant to require general knowledge about your data without needing experience with machine learning or data science..These services provide both REST API(s) and language-based SDKs..As a result, you need to have programming language knowledge to use the services..</p>\", \"id\": null, \"title\": \"Azure AI services and machine learning\", \"filepath\": \"cognitive-services-and-machine-learning.md\", \"url\": \"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\", \"metadata\": {\"chunking\": \"orignal document size=1188. Scores=5.689296 and None.Org Highlight count=160.Filtering to chunk no. 1/Highlights=67 of size=506\"}, \"chunk_id\": \"1\"}, {\"content\": \"<hr />\\n<p>title: Azure AI services and Machine Learning\\ntitleSuffix: Azure AI services\\ndescription: Learn where Azure AI services fits in with other Azure offerings for machine learning.\\nservices: cognitive-services\\nmanager: nitinme\\nauthor: aahill\\nms.author: aahi\\nms.service: cognitive-services\\nms.topic: conceptual\\nms.date: 10/28/2021</p>\\n<hr />\\n<h1 id=\\\"azure-ai-services-and-machine-learning\\\">Azure AI services and machine learning</h1>\\n<p>Azure AI services provides machine learning capabilities to solve general problems such as analyzing text for emotional sentiment or analyzing images to recognize objects or faces..You don't need special machine learning or data science knowledge to use these services../what-are-ai-services.md\\\">Azure AI services</a> is a group of services, each supporting different, generalized prediction capabilities..The services are divided into different categories to help you find the right service..</p>\\n<table>\\n<thead>\\n<tr>\\n<th>Service category</th>\\n<th>Purpose</th>\\n</tr>\\n</thead>\\n<tbody>\\n<tr>\\n<td><a href=\\\"https://azure.microsoft.com/services/cognitive-services/directory/decision/\\\">Decision</a></td>\\n<td>Build apps that surface recommendations for informed and efficient decision-making..</td>\\n</tr>\\n<tr>\\n<td><a href=\\\"https://azure.microsoft.com/services/cognitive-services/directory/lang/\\\">Language</a></td>\\n<td>Allow your apps to process natural language with pre-built scripts, evaluate sentiment and learn how to recognize what users want..</td>\\n</tr>\\n<tr>\\n<td><a href=\\\"https://azure.microsoft.com/services/cognitive-services/directory/search/\\\">Search</a></td>\\n<td>Add Bing Search APIs to your apps and harness the ability to comb billions of webpages, images, videos, and news with a single API call..</td>\\n</tr>\\n<tr>\\n<td><a href=\\\"https://azure.microsoft.com/services/cognitive-services/directory/speech/\\\">Speech</a></td>\", \"id\": null, \"title\": \"Azure AI services and machine learning\", \"filepath\": \"cognitive-services-and-machine-learning.md\", \"url\": \"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\", \"metadata\": {\"chunking\": \"orignal document size=1188. Scores=5.689296 and None.Org Highlight count=160.Filtering to chunk no. 0/Highlights=63 of size=526\"}, \"chunk_id\": \"0\"}, {\"content\": \"<p>How is Azure Cognitive Search related to Azure AI services?</p>\\n<p><a href=\\\"../search/search-what-is-azure-search.md\\\">Azure Cognitive Search</a> is a separate cloud search service that optionally uses Azure AI services to add image and natural language processing to indexing workloads. Azure AI services is exposed in Azure Cognitive Search through <a href=\\\"../search/cognitive-search-predefined-skills.md\\\">built-in skills</a> that wrap individual APIs. You can use a free resource for walkthroughs, but plan on creating and attaching a <a href=\\\"../search/cognitive-search-attach-cognitive-services.md\\\">billable resource</a> for larger volumes.</p>\\n<h2 id=\\\"how-can-you-use-azure-ai-services\\\">How can you use Azure AI services?</h2>\\n<p>Each service provides information about your data. You can combine services together to chain solutions such as converting speech (audio) to text, translating the text into many languages, then using the translated languages to get answers from a knowledge base. While Azure AI services can be used to create intelligent solutions on their own, they can also be combined with traditional machine learning projects to supplement models or accelerate the development process. </p>\\n<p>Azure AI services that provide exported models for other machine learning tools:</p>\\n<table>\\n<thead>\\n<tr>\\n<th>Azure AI service</th>\\n<th>Model information</th>\\n</tr>\\n</thead>\\n<tbody>\\n<tr>\\n<td><a href=\\\"./custom-vision-service/overview.md\\\">Custom Vision</a></td>\\n<td><a href=\\\"./custom-vision-service/export-model-python.md\\\">Export</a> for Tensorflow for Android, CoreML for iOS11, ONNX for Windows ML</td>\\n</tr>\\n</tbody>\\n</table>\\n<h2 id=\\\"learn-more\\\">Learn more</h2>\\n<ul>\\n<li><a href=\\\"/azure/architecture/data-guide/technology-choices/data-science-and-machine-learning\\\">Architecture Guide - What are the machine learning products at Microsoft?</a></li>\\n<li><a href=\\\"../machine-learning/concept-deep-learning-vs-machine-learning.md\\\">Machine learning - Introduction to deep learning vs. machine learning</a></li>\\n</ul>\\n<h2 id=\\\"next-steps\\\">Next steps</h2>\\n<ul>\\n<li>Create your Azure AI services resource in the <a href=\\\"multi-service-resource.md?pivots=azportal\\\">Azure portal</a> or with <a href=\\\"./multi-service-resource.md?pivots=azcli\\\">Azure CLI</a>.</li>\\n<li>Learn how to <a href=\\\"authentication.md\\\">authenticate</a> with your Azure AI service.</li>\\n<li>Use <a href=\\\"diagnostic-logging.md\\\">diagnostic logging</a> for issue identification and debugging. </li>\\n<li>Deploy an Azure AI service in a Docker <a href=\\\"cognitive-services-container-support.md\\\">container</a>.</li>\\n<li>Keep up to date with <a href=\\\"https://azure.microsoft.com/updates/?product=cognitive-services\\\">service updates</a>.</li>\\n</ul>\", \"id\": null, \"title\": \"Azure AI services and machine learning\", \"filepath\": \"cognitive-services-and-machine-learning.md\", \"url\": \"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\", \"metadata\": {\"chunking\": \"orignal document size=793. Scores=3.3767838 and None.Org Highlight count=69.\"}, \"chunk_id\": \"3\"}, {\"content\": \"<p>How are Azure AI services different from machine learning?.</p>\\n<p>Azure AI services provide a trained model for you..This brings data and an algorithm together, available from a REST API(s) or SDK..An Azure AI service provides answers to general problems such as key phrases in text or item identification in images..</p>\\n<p>Machine learning is a process that generally requires a longer period of time to implement successfully..This time is spent on data collection, cleaning, transformation, algorithm selection, model training, and deployment to get to the same level of functionality provided by an Azure AI service..With machine learning, it is possible to provide answers to highly specialized and/or specific problems..Machine learning problems require familiarity with the specific subject matter and data of the problem under consideration, as well as expertise in data science..</p>\\n<h2 id=\\\"what-kind-of-data-do-you-have\\\">What kind of data do you have?.</h2>\\n<p>Azure AI services, as a group of services, can require none, some, or all custom data for the trained model..</p>\\n<h3 id=\\\"no-additional-training-data-required\\\">No additional training data required</h3>\\n<p>Services that provide a fully-trained model can be treated as a <em>opaque box</em>..You don't need to know how they work or what data was used to train them..</p>\\n<h3 id=\\\"some-or-all-training-data-required\\\">Some or all training data required</h3>\\n<p>Some services allow you to bring your own data, then train a model..This allows you to extend the model using the Service's data and algorithm with your own data..The output matches your needs..When you bring your own data, you may need to tag the data in a way specific to the service..For example, if you are training a model to identify flowers, you can provide a catalog of flower images along with the location of the flower in each image to train the model..These services process significant amounts of model data..</p>\\n<h2 id=\\\"service-requirements-for-the-data-model\\\">Service requirements for the data model</h2>\\n<p>The following data categorizes each service by which kind of data it allows or requires..</p>\\n<table>\\n<thead>\\n<tr>\\n<th>Azure AI service</th>\\n<th>No training data required</th>\\n<th>You provide some or all training data</th>\\n<th>Real-time or near real-time data collection</th>\\n</tr>\\n</thead>\\n<tbody>\\n<tr>\\n<td><a href=\\\"../LUIS/what-is-luis.md\\\">Language Understanding (LUIS)</a></td>\\n<td></td>\\n<td>x</td>\\n<td></td>\\n</tr>\\n<tr>\\n<td><a href=\\\"../personalizer/what-is-personalizer.md\\\">Personalizer</a><sup>1</sup></sup></td>\\n<td>x</td>\\n<td>x</td>\\n<td>x</td>\\n</tr>\\n<tr>\\n<td><a href=\\\"../computer-vision/overview.md\\\">Vision</a></td>\\n<td>x</td>\\n<td></td>\\n<td></td>\\n</tr>\\n</tbody>\\n</table>\\n<p><sup>1</sup> Personalizer only needs training data collected by the service (as it operates in real-time) to evaluate your policy and data..</p>\\n<h2 id=\\\"where-can-you-use-azure-ai-services\\\">Where can you use Azure AI services?.</h2>\\n<p>The services are used in any application that can make REST API(s) or SDK calls..Examples of applications include web sites, bots, virtual or mixed reality, desktop and mobile applications.\", \"id\": null, \"title\": \"Azure AI services and machine learning\", \"filepath\": \"cognitive-services-and-machine-learning.md\", \"url\": \"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\", \"metadata\": {\"chunking\": \"orignal document size=1734. Scores=3.1447978 and None.Org Highlight count=66.Filtering to highlight size=891\"}, \"chunk_id\": \"4\"}], \"intent\": \"[\\\"What are the differences between Azure Machine Learning and Azure AI services?\\\"]\"}",
"end_turn": false
}
]
}
}
}
]
}
如果您希望从模型中流式传输响应,可以传递 stream=True
关键字参数:
response = openai.ChatCompletion.create(
messages=[{"role": "user", "content": "What are the differences between Azure Machine Learning and Azure AI services?"}],
deployment_id="gpt-4",
dataSources=[
{
"type": "AzureCognitiveSearch",
"parameters": {
"endpoint": os.environ["SEARCH_ENDPOINT"],
"key": os.environ["SEARCH_KEY"],
"indexName": os.environ["SEARCH_INDEX_NAME"],
}
}
],
stream=True,
)
for chunk in response:
delta = chunk.choices[0].delta
if "role" in delta:
print("\n"+ delta.role + ": ", end="", flush=True)
if "content" in delta:
print(delta.content, end="", flush=True)
if "context" in delta:
print(f"Context: {delta.context}", end="", flush=True)
Context: {
"messages": [
{
"role": "tool",
"content": "{\"citations\":[{\"content\":\"<h2 id=\\\"how-are-azure-ai-services-and-azure-machine-learning-aml-similar\\\">How are Azure AI services and Azure Machine Learning (AML) similar?.</h2>\\n<p>Both have the end-goal of applying artificial intelligence (AI) to enhance business operations, though how each provides this in the respective offerings is different..</p>\\n<p>Generally, the audiences are different:</p>\\n<ul>\\n<li>Azure AI services are for developers without machine-learning experience..</li>\\n<li>Azure Machine Learning is tailored for data scientists.\",\"id\":null,\"title\":\"Azure AI services and machine learning\",\"filepath\":\"cognitive-services-and-machine-learning.md\",\"url\":\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\",\"metadata\":{\"chunking\":\"orignal document size=1188. Scores=5.689296 and None.Org Highlight count=160.Filtering to chunk no. 2/Highlights=30 of size=137\"},\"chunk_id\":\"2\"},{\"content\":\"<td>Convert speech into text and text into natural-sounding speech..Translate from one language to another and enable speaker verification and recognition..</td>\\n</tr>\\n<tr>\\n<td><a href=\\\"https://azure.microsoft.com/services/cognitive-services/directory/vision/\\\">Vision</a></td>\\n<td>Recognize, identify, caption, index, and moderate your pictures, videos, and digital ink content..</td>\\n</tr>\\n<p></tbody>\\n</table></p>\\n<p>Use Azure AI services when you:</p>\\n<ul>\\n<li>Can use a generalized solution..</li>\\n</ul>\\n<p>Use other machine-learning solutions when you:</p>\\n<ul>\\n<li>Need to choose the algorithm and need to train on very specific data..</li>\\n</ul>\\n<h2 id=\\\"what-is-machine-learning\\\">What is machine learning?.</h2>\\n<p>Machine learning is a concept where you bring together data and an algorithm to solve a specific need..Once the data and algorithm are trained, the output is a model that you can use again with different data..The trained model provides insights based on the new data..</p>\\n<p>The process of building a machine learning system requires some knowledge of machine learning or data science..</p>\\n<p>Machine learning is provided using <a href=\\\"/azure/architecture/data-guide/technology-choices/data-science-and-machine-learning?.context=azure%2fmachine-learning%2fstudio%2fcontext%2fml-context\\\">Azure Machine Learning (AML) products and services</a>..</p>\\n<h2 id=\\\"what-is-an-azure-ai-service\\\">What is an Azure AI service?.</h2>\\n<p>An Azure AI service provides part or all of the components in a machine learning solution: data, algorithm, and trained model..These services are meant to require general knowledge about your data without needing experience with machine learning or data science..These services provide both REST API(s) and language-based SDKs..As a result, you need to have programming language knowledge to use the services..</p>\",\"id\":null,\"title\":\"Azure AI services and machine learning\",\"filepath\":\"cognitive-services-and-machine-learning.md\",\"url\":\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\",\"metadata\":{\"chunking\":\"orignal document size=1188. Scores=5.689296 and None.Org Highlight count=160.Filtering to chunk no. 1/Highlights=67 of size=506\"},\"chunk_id\":\"1\"},{\"content\":\"<hr />\\n<p>title: Azure AI services and Machine Learning\\ntitleSuffix: Azure AI services\\ndescription: Learn where Azure AI services fits in with other Azure offerings for machine learning.\\nservices: cognitive-services\\nmanager: nitinme\\nauthor: aahill\\nms.author: aahi\\nms.service: cognitive-services\\nms.topic: conceptual\\nms.date: 10/28/2021</p>\\n<hr />\\n<h1 id=\\\"azure-ai-services-and-machine-learning\\\">Azure AI services and machine learning</h1>\\n<p>Azure AI services provides machine learning capabilities to solve general problems such as analyzing text for emotional sentiment or analyzing images to recognize objects or faces..You don't need special machine learning or data science knowledge to use these services../what-are-ai-services.md\\\">Azure AI services</a> is a group of services, each supporting different, generalized prediction capabilities..The services are divided into different categories to help you find the right service..</p>\\n<table>\\n<thead>\\n<tr>\\n<th>Service category</th>\\n<th>Purpose</th>\\n</tr>\\n</thead>\\n<tbody>\\n<tr>\\n<td><a href=\\\"https://azure.microsoft.com/services/cognitive-services/directory/decision/\\\">Decision</a></td>\\n<td>Build apps that surface recommendations for informed and efficient decision-making..</td>\\n</tr>\\n<tr>\\n<td><a href=\\\"https://azure.microsoft.com/services/cognitive-services/directory/lang/\\\">Language</a></td>\\n<td>Allow your apps to process natural language with pre-built scripts, evaluate sentiment and learn how to recognize what users want..</td>\\n</tr>\\n<tr>\\n<td><a href=\\\"https://azure.microsoft.com/services/cognitive-services/directory/search/\\\">Search</a></td>\\n<td>Add Bing Search APIs to your apps and harness the ability to comb billions of webpages, images, videos, and news with a single API call..</td>\\n</tr>\\n<tr>\\n<td><a href=\\\"https://azure.microsoft.com/services/cognitive-services/directory/speech/\\\">Speech</a></td>\",\"id\":null,\"title\":\"Azure AI services and machine learning\",\"filepath\":\"cognitive-services-and-machine-learning.md\",\"url\":\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\",\"metadata\":{\"chunking\":\"orignal document size=1188. Scores=5.689296 and None.Org Highlight count=160.Filtering to chunk no. 0/Highlights=63 of size=526\"},\"chunk_id\":\"0\"},{\"content\":\"<p>How is Azure Cognitive Search related to Azure AI services?</p>\\n<p><a href=\\\"../search/search-what-is-azure-search.md\\\">Azure Cognitive Search</a> is a separate cloud search service that optionally uses Azure AI services to add image and natural language processing to indexing workloads. Azure AI services is exposed in Azure Cognitive Search through <a href=\\\"../search/cognitive-search-predefined-skills.md\\\">built-in skills</a> that wrap individual APIs. You can use a free resource for walkthroughs, but plan on creating and attaching a <a href=\\\"../search/cognitive-search-attach-cognitive-services.md\\\">billable resource</a> for larger volumes.</p>\\n<h2 id=\\\"how-can-you-use-azure-ai-services\\\">How can you use Azure AI services?</h2>\\n<p>Each service provides information about your data. You can combine services together to chain solutions such as converting speech (audio) to text, translating the text into many languages, then using the translated languages to get answers from a knowledge base. While Azure AI services can be used to create intelligent solutions on their own, they can also be combined with traditional machine learning projects to supplement models or accelerate the development process. </p>\\n<p>Azure AI services that provide exported models for other machine learning tools:</p>\\n<table>\\n<thead>\\n<tr>\\n<th>Azure AI service</th>\\n<th>Model information</th>\\n</tr>\\n</thead>\\n<tbody>\\n<tr>\\n<td><a href=\\\"./custom-vision-service/overview.md\\\">Custom Vision</a></td>\\n<td><a href=\\\"./custom-vision-service/export-model-python.md\\\">Export</a> for Tensorflow for Android, CoreML for iOS11, ONNX for Windows ML</td>\\n</tr>\\n</tbody>\\n</table>\\n<h2 id=\\\"learn-more\\\">Learn more</h2>\\n<ul>\\n<li><a href=\\\"/azure/architecture/data-guide/technology-choices/data-science-and-machine-learning\\\">Architecture Guide - What are the machine learning products at Microsoft?</a></li>\\n<li><a href=\\\"../machine-learning/concept-deep-learning-vs-machine-learning.md\\\">Machine learning - Introduction to deep learning vs. machine learning</a></li>\\n</ul>\\n<h2 id=\\\"next-steps\\\">Next steps</h2>\\n<ul>\\n<li>Create your Azure AI services resource in the <a href=\\\"multi-service-resource.md?pivots=azportal\\\">Azure portal</a> or with <a href=\\\"./multi-service-resource.md?pivots=azcli\\\">Azure CLI</a>.</li>\\n<li>Learn how to <a href=\\\"authentication.md\\\">authenticate</a> with your Azure AI service.</li>\\n<li>Use <a href=\\\"diagnostic-logging.md\\\">diagnostic logging</a> for issue identification and debugging. </li>\\n<li>Deploy an Azure AI service in a Docker <a href=\\\"cognitive-services-container-support.md\\\">container</a>.</li>\\n<li>Keep up to date with <a href=\\\"https://azure.microsoft.com/updates/?product=cognitive-services\\\">service updates</a>.</li>\\n</ul>\",\"id\":null,\"title\":\"Azure AI services and machine learning\",\"filepath\":\"cognitive-services-and-machine-learning.md\",\"url\":\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\",\"metadata\":{\"chunking\":\"orignal document size=793. Scores=3.3767838 and None.Org Highlight count=69.\"},\"chunk_id\":\"3\"},{\"content\":\"<p>How are Azure AI services different from machine learning?.</p>\\n<p>Azure AI services provide a trained model for you..This brings data and an algorithm together, available from a REST API(s) or SDK..An Azure AI service provides answers to general problems such as key phrases in text or item identification in images..</p>\\n<p>Machine learning is a process that generally requires a longer period of time to implement successfully..This time is spent on data collection, cleaning, transformation, algorithm selection, model training, and deployment to get to the same level of functionality provided by an Azure AI service..With machine learning, it is possible to provide answers to highly specialized and/or specific problems..Machine learning problems require familiarity with the specific subject matter and data of the problem under consideration, as well as expertise in data science..</p>\\n<h2 id=\\\"what-kind-of-data-do-you-have\\\">What kind of data do you have?.</h2>\\n<p>Azure AI services, as a group of services, can require none, some, or all custom data for the trained model..</p>\\n<h3 id=\\\"no-additional-training-data-required\\\">No additional training data required</h3>\\n<p>Services that provide a fully-trained model can be treated as a <em>opaque box</em>..You don't need to know how they work or what data was used to train them..</p>\\n<h3 id=\\\"some-or-all-training-data-required\\\">Some or all training data required</h3>\\n<p>Some services allow you to bring your own data, then train a model..This allows you to extend the model using the Service's data and algorithm with your own data..The output matches your needs..When you bring your own data, you may need to tag the data in a way specific to the service..For example, if you are training a model to identify flowers, you can provide a catalog of flower images along with the location of the flower in each image to train the model..These services process significant amounts of model data..</p>\\n<h2 id=\\\"service-requirements-for-the-data-model\\\">Service requirements for the data model</h2>\\n<p>The following data categorizes each service by which kind of data it allows or requires..</p>\\n<table>\\n<thead>\\n<tr>\\n<th>Azure AI service</th>\\n<th>No training data required</th>\\n<th>You provide some or all training data</th>\\n<th>Real-time or near real-time data collection</th>\\n</tr>\\n</thead>\\n<tbody>\\n<tr>\\n<td><a href=\\\"../LUIS/what-is-luis.md\\\">Language Understanding (LUIS)</a></td>\\n<td></td>\\n<td>x</td>\\n<td></td>\\n</tr>\\n<tr>\\n<td><a href=\\\"../personalizer/what-is-personalizer.md\\\">Personalizer</a><sup>1</sup></sup></td>\\n<td>x</td>\\n<td>x</td>\\n<td>x</td>\\n</tr>\\n<tr>\\n<td><a href=\\\"../computer-vision/overview.md\\\">Vision</a></td>\\n<td>x</td>\\n<td></td>\\n<td></td>\\n</tr>\\n</tbody>\\n</table>\\n<p><sup>1</sup> Personalizer only needs training data collected by the service (as it operates in real-time) to evaluate your policy and data..</p>\\n<h2 id=\\\"where-can-you-use-azure-ai-services\\\">Where can you use Azure AI services?.</h2>\\n<p>The services are used in any application that can make REST API(s) or SDK calls..Examples of applications include web sites, bots, virtual or mixed reality, desktop and mobile applications.\",\"id\":null,\"title\":\"Azure AI services and machine learning\",\"filepath\":\"cognitive-services-and-machine-learning.md\",\"url\":\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\",\"metadata\":{\"chunking\":\"orignal document size=1734. Scores=3.1447978 and None.Org Highlight count=66.Filtering to highlight size=891\"},\"chunk_id\":\"4\"}],\"intent\":\"[\\\"What are the differences between Azure Machine Learning and Azure AI services?\\\"]\"}",
"end_turn": false
}
]
}
assistant: Azure AI services and Azure Machine Learning (AML) both aim to apply artificial intelligence (AI) to enhance business operations, but they target different audiences and offer different capabilities [doc1].
Azure AI services are designed for developers without machine learning experience and provide pre-trained models to solve general problems such as text analysis, image recognition, and natural language processing [doc5]. These services require general knowledge about your data without needing experience with machine learning or data science and provide REST APIs and language-based SDKs [doc2].
On the other hand, Azure Machine Learning is tailored for data scientists and offers a platform to build, train, and deploy custom machine learning models [doc1]. It requires knowledge of machine learning or data science and allows users to choose the algorithm and train on very specific data [doc2].
In summary, Azure AI services offer pre-trained models for developers without machine learning experience, while Azure Machine Learning is a platform for data scientists to build and deploy custom machine learning models.