Skip to content

Commit bb092ec

Browse files
authored
Merge pull request #1371 from sdgilley/sdg-release-sdk
update sdk overview for ignite
2 parents 16cb945 + 2a6a305 commit bb092ec

File tree

1 file changed

+278
-32
lines changed

1 file changed

+278
-32
lines changed

articles/ai-studio/how-to/develop/sdk-overview.md

Lines changed: 278 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,303 @@ ms.service: azure-ai-studio
77
ms.custom:
88
- build-2024
99
ms.topic: overview
10-
ms.date: 8/9/2024
10+
ms.date: 11/07/2024
1111
ms.reviewer: dantaylo
1212
ms.author: sgilley
1313
author: sdgilley
1414
---
1515

16-
# Overview of the Azure AI SDKs
16+
# The Azure AI Foundry SDK
1717

18-
Microsoft offers a variety of packages that you can use for building generative AI applications in the cloud. In most applications, you need to use a combination of packages to manage and use various Azure services that provide AI functionality. We also offer integrations with open-source libraries like LangChain and MLflow for use with Azure. In this article we'll give an overview of the main services and SDKs you can use with Azure AI Studio.
18+
The Azure AI Foundry SDK is a comprehensive toolchain designed to simplify the development of AI applications on Azure. It enables developers to:
1919

20-
For building generative AI applications, we recommend using the following services and SDKs:
21-
* [Azure Machine Learning](/azure/machine-learning/overview-what-is-azure-machine-learning) for the hub and project infrastructure used in AI Studio to organize your work into projects, manage project artifacts (data, evaluation runs, traces), fine-tune & deploy models, and connect to external services and resources.
22-
* [Azure AI services](../../../ai-services/what-are-ai-services.md) provides pre-built and customizable intelligent APIs and models, with support for Azure OpenAI, Azure AI Search, Speech, Vision, and Language.
23-
* [Prompt flow](https://microsoft.github.io/promptflow/index.html) for developer tools to streamline the end-to-end development cycle of LLM-based AI application, with support for inferencing, indexing, evaluation, deployment, and monitoring.
20+
- Access popular models from various model providers through a single interface
21+
- Easily combine together models, data, and AI services to build AI-powered applications
22+
- Evaluate, debug, and improve application quality & safety across development, testing, and production environments
23+
24+
The AI Foundry SDK is a set of packages and services designed to work together. You can use the Azure AI Projects client library to easily use multiple services through a single project client and connection string. You can also use services and SDKs on their own and connect directly to your services.
2425

25-
For each of these, there are separate sets of management libraries and client libraries.
26+
If you want to jump right in and start building an app, check out:
27+
- [Create a chat app](../../quickstarts/get-started-code.md)
28+
- [Create a custom RAG app](../../tutorials/copilot-sdk-create-resources.md)
2629

27-
## Management libraries for creating and managing cloud resources
30+
## Get started with Projects
2831

29-
Azure [management libraries](/azure/developer/python/sdk/azure-sdk-overview#create-and-manage-azure-resources-with-management-libraries) (also "control plane" or "management plane"), for creating and managing cloud resources that are used by your application.
32+
The best way to get started using the Azure AI Foundry SDK is by using a project. AI projects connect together different data, assets, and services you need to build AI applications. The AI project client allows you to easily access these project components from your code by using a single connection string.
3033

31-
Azure Machine Learning
32-
* [Azure Machine Learning Python SDK (v2)](/python/api/overview/azure/ai-ml-readme)
33-
* [Azure Machine Learning CLI (v2)](/azure/machine-learning/how-to-configure-cli?view=azureml-api-2&tabs=public)
34-
* [Azure Machine Learning REST API](/rest/api/azureml)
34+
First follow steps to [create an AI Project](../create-projects.md) if you don't have one already.
3535

36-
Azure AI services
37-
* [Azure AI Services Python Management Library](/python/api/overview/azure/mgmt-cognitiveservices-readme?view=azure-python)
38-
* [Azure AI Search Python Management Library](/python/api/azure-mgmt-search/azure.mgmt.search?view=azure-python)
39-
* [Azure CLI commands for Azure AI Search](/azure/search/search-manage-azure-cli)
40-
* [Azure CLI commands for Azure AI Services](/cli/azure/cognitiveservices?view=azure-cli-latest)
36+
Sign in with the Azure CLI using the same account that you use to access your AI Project:
4137

42-
Prompt flow
43-
* [pfazure CLI](https://microsoft.github.io/promptflow/reference/pfazure-command-reference.html)
44-
* [pfazure Python library](https://microsoft.github.io/promptflow/reference/python-library-reference/promptflow-azure/promptflow.azure.html)
38+
```
39+
az login
40+
```
41+
42+
Install the Azure AI projects client library:
43+
44+
```
45+
pip install azure-ai-projects azure-identity
46+
```
47+
48+
Create a project client in code:
49+
50+
# [Sync](#tab/sync)
51+
52+
```Python
53+
from azure.identity import DefaultAzureCredential
54+
from azure.ai.projects import AIProjectClient
55+
56+
project_connection_string="your_connection_string"
57+
58+
project = AIProjectClient.from_connection_string(
59+
conn_str=project_connection_string,
60+
credential=DefaultAzureCredential())
61+
```
62+
63+
# [Async](#tab/async)
64+
65+
```Python
66+
from azure.identity.aio import DefaultAzureCredential
67+
from azure.ai.projects.aio import AIProjectClient
68+
69+
project_connection_string="your_connection_string"
70+
71+
project = await AIProjectClient.from_connection_string(
72+
conn_str=project_connection_string,
73+
credential=DefaultAzureCredential())
74+
```
75+
76+
---
77+
78+
Copy the **Project connection string** from the **Overview** page of the project and update the `project_connection_string` variable above.
79+
80+
Once you have created the project client, you can use the client for the capabilities in the following sections.
81+
82+
Be sure to check out the [reference]() and [samples](https://aka.ms/azsdk/azure-ai-projects/python/samples).
83+
84+
## Azure OpenAI Service
85+
86+
If you have existing code that uses the OpenAI SDK, you can use the project client to create an ```AzureOpenAI``` client that uses your project's Azure OpenAI connection.
87+
```
88+
pip install openai
89+
```
90+
91+
Now use the project client to return an ```AzureOpenAI``` client with the desired API version and make a chat completions call.
92+
93+
```Python
94+
openai = project.inference.get_azure_openai_client(api_version="2024-06-01")
95+
response = openai.chat.completions.create(
96+
model="gpt-4o",
97+
messages=[
98+
{"role": "system", "content": "You are a helpful writing assistant"},
99+
{"role": "user", "content": "Write me a poem about flowers"},
100+
]
101+
)
102+
103+
print(response.choices[0].message.content)
104+
```
105+
106+
For more on using the Azure OpenAI client library, including how to use it directly against with the Azure OpenAI Service, check out [Azure OpenAI chat quickstart](../../../ai-services/openai/chatgpt-quickstart.md).
107+
108+
## Azure AI model inference service
109+
110+
The [Azure AI model inference service](/azure/ai-studio/ai-services/model-inference) offers access to powerful models from leading providers like OpenAI, Microsoft, Meta, and more. These models support tasks such as content generation, summarization, and code generation.
111+
112+
To use the model inference service, first ensure that your project has an AI Services connection (in the management center).
113+
114+
Install the ```azure-ai-inferencing``` client library:
115+
116+
```
117+
pip install azure-ai-inference
118+
```
119+
120+
You can use the project client to get a configured and authenticated ```ChatCompletionsClient``` or ```EmbeddingsClient```:
121+
122+
```Python
123+
# get an chat inferencing client using the project's default model inferencing endpoint
124+
chat = project.inference.get_chat_completions_client()
125+
126+
# run a chat completion using the inferencing client
127+
response = chat.complete(
128+
model="gpt-4o",
129+
messages=[
130+
{"role": "system", "content": "You are a helpful writing assistant"},
131+
{"role": "user", "content": "Write me a poem about flowers"},
132+
]
133+
)
134+
135+
print(response.choices[0].message.content)
136+
```
137+
138+
You can change the model name to any model that you deployed to the inference service or Azure OpenAI service.
139+
140+
To learn more about using the Azure AI inferencing client, check out the [Azure AI model inferencing reference](/azure/ai-studio/reference/reference-model-inference-api).
141+
142+
## Prompt Templates
143+
144+
The inferencing client supports for creating prompt messages from templates. The template allows you to dynamically generate prompts using inputs that are available at runtime.
145+
146+
To use prompt templates, install the `azure-ai-inferencing` package:
147+
148+
```
149+
pip install azure-ai-inference
150+
```
151+
152+
You can render a prompt template from an inline string:
153+
154+
```Python
155+
from azure.ai.inference.prompts import PromptTemplate
156+
157+
# create a prompt template from an inline string (using mustache syntax)
158+
prompt_template = PromptTemplate.from_string(prompt_template="""
159+
system:
160+
You are a helpful writing assistant.
161+
The user's first name is {{first_name}} and their last name is {{last_name}}.
162+
163+
user:
164+
Write me a poem about flowers
165+
""")
166+
167+
# generate system message from the template, passing in the context as variables
168+
messages = prompt_template.create_messages(first_name="Jane", last_name="Doe")
169+
print(messages)
170+
```
45171

46-
## Client libraries used in runtime application code
172+
This code outputs messages that you can then pass to a chat completions call:
47173

48-
Azure [Client libraries](/azure/developer/python/sdk/azure-sdk-overview#connect-to-and-use-azure-resources-with-client-libraries) (also called "data plane") for connecting to and using provisioned services from runtime application code.
174+
```text
175+
[
176+
{'role': 'system', 'content': "You are a helpful writing assistant.\nThe user's first name is Jane and their last name is Doe."}
177+
{'role': 'user', 'content': 'Write me a poem about flowers'}
178+
]
179+
```
180+
181+
NOTE: leading whitespace is automatically trimmed from input strings.
182+
183+
You can also load prompts from a [`Prompty`](https://prompty.ai) file, enabling you to also load the model name and parameters from the `.prompty` file:
184+
185+
```Python
186+
from azure.ai.inference.prompts import PromptTemplate
187+
188+
prompt_template = PromptTemplate.from_prompty("myprompt.prompty")
189+
messages = prompt_template.create_messages(first_name="Jane", last_name="Doe")
190+
191+
response = chat.complete(
192+
messages=messages,
193+
model=prompt_template.model_name,
194+
**prompt_template.parameters,
195+
)
196+
```
197+
198+
## Azure AI Search
199+
200+
If you have an Azure AI Search resource connected to your project, you can also use the project client to create an Azure AI Search client using the project connection.
201+
202+
Install the Azure AI Search client library:
203+
204+
```
205+
pip install azure-search-documents
206+
```
207+
208+
Instantiate the search and/or search index client as desired:
209+
210+
```Python
211+
from azure.core.credentials import AzureKeyCredential
212+
from azure.ai.projects.models import ConnectionType
213+
from azure.search.documents import SearchClient
214+
from azure.search.documents.indexes import SearchIndexClient
215+
216+
# use the project client to get the default search connection
217+
search_connection = project.connections.get_default(
218+
connection_type=ConnectionType.AZURE_AI_SEARCH,
219+
with_credentials=True)
220+
221+
# Create a client to create and manage search indexes
222+
index_client = SearchIndexClient(
223+
endpoint=search_connection.endpoint_url,
224+
credential=AzureKeyCredential(key=search_connection.key)
225+
)
226+
227+
# Create a client to run search queries
228+
search_client = SearchClient(
229+
index_name="your_index_name",
230+
endpoint=search_connection.endpoint_url,
231+
credential=AzureKeyCredential(key=search_connection.key)
232+
)
233+
```
234+
235+
To learn more about using Azure AI Search, check out [Azure AI Search documentation](/azure/search/).
236+
237+
## Azure AI agents runtime
238+
239+
Azure AI Agent Service is a fully managed service designed to empower developers to securely build, deploy, and scale high-quality, and extensible AI agents. Using an extensive ecosystem of models, tools and capabilities from OpenAI, Microsoft, and third-party providers, Azure AI Agent Service enables building agents for a wide range of generative AI use cases.
240+
241+
To get access to agents, [sign-up for the private preview]().
242+
243+
## Evaluation
244+
245+
You can use the project client to easily connect to the Azure AI evaluation service, and models needed for running your evaluators.
246+
247+
Using the ```project.scope``` parameter, we can easily instantiate a ```ViolenceEvaluator```:
248+
```Python
249+
from azure.ai.evaluation import ViolenceEvaluator
250+
from azure.identity import DefaultAzureCredential
251+
252+
# Initializing Violence Evaluator with project information
253+
violence_eval = ViolenceEvaluator(
254+
azure_ai_project=project.scope,
255+
credential=DefaultAzureCredential())
256+
257+
# Running Violence Evaluator on single input row
258+
violence_score = violence_eval(query="what's the capital of france", response="Paris")
259+
print(violence_score)
260+
```
261+
262+
To learn more, check out [Evaluation using the SDK](evaluate-sdk.md).
263+
264+
## Tracing
265+
266+
To enable tracing, first ensure your project has an attached Application Insights resource. Go to the **Tracing** page of your project and follow instructions to create or attach Application Insights.
267+
268+
```Python
269+
# Enable instrumentation of AI packages (inference, agents, openai, langchain)
270+
project.telemetry.enable()
271+
272+
# Log traces to the project's application insights resource
273+
application_insights_connection_string = project.telemetry.get_connection_string()
274+
if application_insights_connection_string:
275+
configure_azure_monitor(connection_string=application_insights_connection_string)
276+
```
277+
278+
## Related content
279+
280+
Below are some helpful links to other services and frameworks that you can use with the Azure AI Foundry SDK.
281+
282+
### Azure AI Services
283+
284+
Client libraries:
285+
286+
* [Azure AI services SDKs](../../../ai-services/reference/sdk-package-resources.md?context=/azure/ai-studio/context/context)
287+
* [Azure AI services REST APIs](../../../ai-services/reference/rest-api-resources.md?context=/azure/ai-studio/context/context)
49288

50289
Azure AI services
51-
* [Azure AI services SDKs](../../../ai-services/reference/sdk-package-resources.md?context=/azure/ai-studio/context/context)
52-
* [Azure AI services REST APIs](../../../ai-services/reference/rest-api-resources.md?context=/azure/ai-studio/context/context)
290+
* [Azure AI Services Python Management Library](/python/api/overview/azure/mgmt-cognitiveservices-readme)
291+
* [Azure AI Search Python Management Library](/python/api/azure-mgmt-search/azure.mgmt.search)
292+
293+
### Frameworks
294+
295+
Azure Machine Learning
296+
297+
* [Azure Machine Learning Python SDK (v2)](/python/api/overview/azure/ai-ml-readme)
298+
* [Azure Machine Learning CLI (v2)](/azure/machine-learning/how-to-configure-cli)
299+
* [Azure Machine Learning REST API](/rest/api/azureml)
53300

54301
Prompt flow
55-
* [Prompt flow SDK](https://microsoft.github.io/promptflow/how-to-guides/quick-start.html)
56302

57-
Agentic frameworks:
58-
* [LlamaIndex](llama-index.md)
303+
* [Prompt flow SDK](https://microsoft.github.io/promptflow/how-to-guides/quick-start.html)
304+
* [pfazure CLI](https://microsoft.github.io/promptflow/reference/pfazure-command-reference.html)
305+
* [pfazure Python library](https://microsoft.github.io/promptflow/reference/python-library-reference/promptflow-azure/promptflow.azure.html)
59306

60-
## Related content
307+
Agentic frameworks
61308

62-
- [Get started building a chat app using the prompt flow SDK](../../quickstarts/get-started-code.md)
63-
- [Work with projects in VS Code](vscode.md)
309+
* [LlamaIndex](llama-index.md)

0 commit comments

Comments
 (0)