Skip to content

Commit 45bcc44

Browse files
committed
Merge branch 'main' of https://github.com/qubitron/azure-ai-docs-pr into sdg-release-sdk
2 parents ae0fe11 + 87ffae4 commit 45bcc44

File tree

1 file changed

+254
-27
lines changed

1 file changed

+254
-27
lines changed

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

Lines changed: 254 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,278 @@ 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 well 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 connects 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+
Login with the Azure CLI using the same account that you use to access your AI Project:
37+
```
38+
az login
39+
```
4140

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)
41+
Install the Azure AI projects client library:
42+
```
43+
pip install azure-ai-projects azure-identity
44+
```
4545

46-
## Client libraries used in runtime application code
46+
Create a project client in code:
4747

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.
48+
Sync Tab:
49+
```Python
50+
from azure.identity import DefaultAzureCredential
51+
from azure.ai.projects import AIProjectClient
52+
53+
project_connection_string="your_connection_string"
4954

50-
Azure AI services
55+
project = AIProjectClient.from_connection_string(
56+
conn_str=project_connection_string,
57+
credential=DefaultAzureCredential())
58+
```
59+
60+
Async Tab:
61+
```Python
62+
from azure.identity.aio import DefaultAzureCredential
63+
from azure.ai.projects.aio import AIProjectClient
64+
65+
project_connection_string="your_connection_string"
66+
67+
project = await AIProjectClient.from_connection_string(
68+
conn_str=project_connection_string,
69+
credential=DefaultAzureCredential())
70+
```
71+
72+
Copy the **Project connection string** from the **Overview** page of the project and update the ```project_connection_string``` variable above.
73+
74+
Once you have created the project client, you can use the client for the capabilities in the following sections.
75+
76+
Be sure to check out the [reference](https://aka.ms/azsdk/azure-ai-projects/python/reference) and [samples](https://aka.ms/azsdk/azure-ai-projects/python/samples).
77+
78+
## Azure OpenAI Service
79+
80+
If you have existing code that leverages the OpenAI SDK, you can use the project client to create an ```AzureOpenAI``` client that leverages your project's Azure OpenAI connection.
81+
```
82+
pip install openai
83+
```
84+
85+
Now use the project client to return an ```AzureOpenAI``` client with the desired API version and make a chat completions call.
86+
```Python
87+
openai = project.inference.get_azure_openai_client(api_version="2024-06-01")
88+
response = openai.chat.completions.create(
89+
model="gpt-4o",
90+
messages=[
91+
{"role": "system", "content": "You are a helpful writing assistant"},
92+
{"role": "user", "content": "Write me a poem about flowers"},
93+
]
94+
)
95+
96+
print(response.choices[0].message.content)
97+
```
98+
99+
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).
100+
101+
## Azure AI model inference service
102+
103+
The [Azure AI model inference service](https://learn.microsoft.com/en-us/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.
104+
105+
To use the model inference service, first ensure that your project has an AI Services connection (in the management center).
106+
107+
Install the ```azure-ai-inferencing``` client library:
108+
```
109+
pip install azure-ai-inference
110+
```
111+
112+
You can use the project client to get a configured and authenticated ```ChatCompletionsClient``` or ```EmbeddingsClient```:
113+
```Python
114+
# get an chat inferencing client using the project's default model inferencing endpoint
115+
chat = project.inference.get_chat_completions_client()
116+
117+
# run a chat completion using the inferencing client
118+
response = chat.complete(
119+
model="gpt-4o",
120+
messages=[
121+
{"role": "system", "content": "You are a helpful writing assistant"},
122+
{"role": "user", "content": "Write me a poem about flowers"},
123+
]
124+
)
125+
126+
print(response.choices[0].message.content)
127+
```
128+
129+
You can change the model name to any model that you have deployed to the inference service or Azure OpenAI service.
130+
131+
To learn more about using the Azure AI inferencing client, check out the [Azure AI model inferencing reference](https://learn.microsoft.com/en-us/azure/ai-studio/reference/reference-model-inference-api?tabs=python).
132+
133+
## Prompt Templates
134+
135+
The inferencing client supports for creating prompt messages from templates, this allows you to dynamically generate prompts using inputs that are available at runtime.
136+
137+
To use prompt templates, install the ```azure-ai-inferencing``` package:
138+
```
139+
pip install azure-ai-inference
140+
```
141+
142+
You can render a prompt template from an inline string:
143+
```Python
144+
from azure.ai.inference.prompts import PromptTemplate
145+
146+
# create a prompt template from an inline string (using mustache syntax)
147+
prompt_template = PromptTemplate.from_string(prompt_template="""
148+
system:
149+
You are a helpful writing assistant.
150+
The user's first name is {{first_name}} and their last name is {{last_name}}.
151+
152+
user:
153+
Write me a poem about flowers
154+
""")
155+
156+
# generate system message from the template, passing in the context as variables
157+
messages = prompt_template.create_messages(first_name="Jane", last_name="Doe")
158+
print(messages)
159+
```
160+
This will output messages that you can then pass to a chat completions call:
161+
```
162+
[
163+
{'role': 'system', 'content': "You are a helpful writing assistant.\nThe user's first name is Jane and their last name is Doe."}
164+
{'role': 'user', 'content': 'Write me a poem about flowers'}
165+
]
166+
```
167+
NOTE: leading whitespace is automatically trimmed from input strings.
168+
169+
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:
170+
```Python
171+
from azure.ai.inference.prompts import PromptTemplate
172+
173+
prompt_template = PromptTemplate.from_prompty("myprompt.prompty")
174+
messages = prompt_template.create_messages(first_name="Jane", last_name="Doe")
175+
176+
response = chat.complete(
177+
messages=messages,
178+
model=prompt_template.model_name,
179+
**prompt_template.parameters,
180+
)
181+
```
182+
183+
## Azure AI Search
184+
185+
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.
186+
187+
Install the Azure AI Search client library:
188+
```
189+
pip install azure-search-documents
190+
```
191+
192+
Instantiate the search and/or search index client as desired:
193+
```Python
194+
from azure.core.credentials import AzureKeyCredential
195+
from azure.ai.projects.models import ConnectionType
196+
from azure.search.documents import SearchClient
197+
from azure.search.documents.indexes import SearchIndexClient
198+
199+
# use the project client to get the default search connection
200+
search_connection = project.connections.get_default(
201+
connection_type=ConnectionType.AZURE_AI_SEARCH,
202+
with_credentials=True)
203+
204+
# Create a client to create and manage search indexes
205+
index_client = SearchIndexClient(
206+
endpoint=search_connection.endpoint_url,
207+
credential=AzureKeyCredential(key=search_connection.key)
208+
)
209+
210+
# Create a client to run search queries
211+
search_client = SearchClient(
212+
index_name="your_index_name",
213+
endpoint=search_connection.endpoint_url,
214+
credential=AzureKeyCredential(key=search_connection.key)
215+
)
216+
```
217+
218+
To learn more about using Azure AI Search, check out [Azure AI Search documentation](https://learn.microsoft.com/azure/search/).
219+
220+
## Azure AI agents runtime
221+
222+
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. Leveraging 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.
223+
224+
To get access to agents, [sign-up for the private preview](TODO).
225+
226+
## Evaluation
227+
228+
You can leverage the project client to easily connect to the Azure AI evaluation service, and models needed for running your evaluators.
229+
230+
Using the ```project.scope``` parameter, we can easily instantiate a ```ViolenceEvaluator```:
231+
```Python
232+
from azure.ai.evaluation import ViolenceEvaluator
233+
from azure.identity import DefaultAzureCredential
234+
235+
# Initializing Violence Evaluator with project information
236+
violence_eval = ViolenceEvaluator(
237+
azure_ai_project=project.scope,
238+
credential=DefaultAzureCredential())
239+
240+
# Running Violence Evaluator on single input row
241+
violence_score = violence_eval(query="what's the capital of france", response="Paris")
242+
print(violence_score)
243+
```
244+
245+
To learn more, check out [Evaluation using the SDK](evaluate_sdk.md).
246+
247+
## Tracing
248+
249+
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.
250+
251+
```Python
252+
# Enable instrumentation of AI packages (inference, agents, openai, langchain)
253+
project.telemetry.enable()
254+
255+
# Log traces to the project's application insights resource
256+
application_insights_connection_string = project.telemetry.get_connection_string()
257+
if application_insights_connection_string:
258+
configure_azure_monitor(connection_string=application_insights_connection_string)
259+
```
260+
261+
## Additional AI Services and Frameworks
262+
263+
Below are some helpful links to additional services and frameworks that you can use with the Azure AI Foundry SDK.
264+
265+
### Azure AI Services
266+
267+
Client libraries:
51268
* [Azure AI services SDKs](../../../ai-services/reference/sdk-package-resources.md?context=/azure/ai-studio/context/context)
52269
* [Azure AI services REST APIs](../../../ai-services/reference/rest-api-resources.md?context=/azure/ai-studio/context/context)
53270

271+
Azure AI services
272+
* [Azure AI Services Python Management Library](/python/api/overview/azure/mgmt-cognitiveservices-readme?view=azure-python)
273+
* [Azure AI Search Python Management Library](/python/api/azure-mgmt-search/azure.mgmt.search?view=azure-python)
274+
275+
### Frameworks
276+
277+
Azure Machine Learning
278+
* [Azure Machine Learning Python SDK (v2)](/python/api/overview/azure/ai-ml-readme)
279+
* [Azure Machine Learning CLI (v2)](/azure/machine-learning/how-to-configure-cli?view=azureml-api-2&tabs=public)
280+
* [Azure Machine Learning REST API](/rest/api/azureml)
281+
54282
Prompt flow
55283
* [Prompt flow SDK](https://microsoft.github.io/promptflow/how-to-guides/quick-start.html)
284+
* [pfazure CLI](https://microsoft.github.io/promptflow/reference/pfazure-command-reference.html)
285+
* [pfazure Python library](https://microsoft.github.io/promptflow/reference/python-library-reference/promptflow-azure/promptflow.azure.html)
56286

57287
Agentic frameworks:
58288
* [LlamaIndex](llama-index.md)
59289

60-
## Related content
61290

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)

0 commit comments

Comments
 (0)