Skip to content

Commit 7a98d89

Browse files
sophia-ramseytrangevinick863
authored
Azure.AI.Projects beta 10 (Azure#51096)
* Sramsey/datasets (Azure#50459) * regenerate code based on commit 06308c1 * change return type of `UploadFile` and `UploadFolder` from Response to DatasetVersion to better align with python + js * add connectionName input for `UploadFile` and `UploadFolder` * update snippets + api * add datasets regex filter (Azure#50649) * add optional regex filter for UploadFolder * update samples/api * regenerate code / remove body from datasets (Azure#50767) * regenerate code / remove body from datasets * update changelog * [Azure.AI.Projects] Remove Inference related code (Azure#50774) * Remove Inference related code. Modify samples to just use the base Inference client, by modifying the project endpoint Signed-off-by: trangevi <[email protected]> * missed the package dependency Signed-off-by: trangevi <[email protected]> * Missed an import Signed-off-by: trangevi <[email protected]> * Update snippets. Update readme Signed-off-by: trangevi <[email protected]> * API updates Signed-off-by: trangevi <[email protected]> * snippet fixes Signed-off-by: trangevi <[email protected]> --------- Signed-off-by: trangevi <[email protected]> * change string to uri (Azure#50831) * change DataUri, BlobUri, and SasUri from type string to uri, update references * update api to reflect changes * replace GetClient() with properties (Azure#50893) * add functionality to use `Connections`, `Datasets`, `Deployments`, and `Indexes` properties instead of `GetConnectionsClient()`, `GetDatasetsClient()`, `GetDeploymentsClient()`, and `GetIndexesClient()` * update changelog, samples, and api * still left to do: mark `GetConnectionsClient()`, `GetDatasetsClient()`, `GetDeploymentsClient()`, and `GetIndexesClient()` as internal * change Get*Client() functions to internal (Azure#50943) * update custom code for `GetConnectionsClient()`, `GetDatasetsClient()`, `GetDeploymentsClient()`, `GetEvaluationsClient()`, `GetIndexesClient()`, and `GetRedteamsClient()` to be internal * update api and samples * emitted the code with `generate-sample-project: false`, so that Generated/Docs and Generated/Samples would not be generated to use internal functions * add GetModelDeployment (Azure#50964) * rename connection, index, SasCredential, Sku (Azure#50997) * rename connection, index, SasCredential, Sku * update changelog * rename deployment (Azure#51000) * Add aoai embeddings (Azure#51095) * add aoai text embeddings * update model_deployment_name * Additional fixes for dataset upload (Azure#51138) * Fix authentication on data sets * Allow entra ID auth if SAS is not available * address comments (Azure#51222) --------- Signed-off-by: trangevi <[email protected]> Co-authored-by: trangevi <[email protected]> Co-authored-by: Nikolay Rovinskiy <[email protected]>
1 parent afa5d15 commit 7a98d89

File tree

89 files changed

+1589
-6088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1589
-6088
lines changed

sdk/ai/Azure.AI.Projects/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
## 1.0.0-beta.10 (Unreleased)
44

55
### Features Added
6+
* Support for generating embeddings through Azure OpenAI using `GetAzureOpenAIEmbeddingClient`.
67

78
### Breaking Changes
9+
* Name changes:
10+
* In `Datasets` methods `PendingUpload` and `PendingUploadAsync`, argument `body` was replaced with `pendingUploadRequest`
11+
* `Connection` has been renamed `ConnectionProperties`
12+
* `Deployment` has been renamed `AIDeployment`
13+
* `Index` has been renamed `DatasetIndex`
14+
* `SasCredential` has been renamed `BlobReferenceSasCredential`
15+
* `Sku` has been renamed `ModelDeploymentSku`
16+
* Removing `GetChatCompletionsClient`, `GetEmbeddingsClient`, and `GetImageEmbeddingsClient` methods from `AIProjectClient`. The Inference client should be used directly instead.
17+
* Replacing `GetConnectionsClient`, `GetDatasetsClient`, `GetDeploymentsClient`, and`GetIndexesClient` with `Connections`, `Datasets`, `Deployments`, and `Indexes` properties.
818

919
### Bugs Fixed
1020
* Fix getting model deployed on the Azure Open AI resource, if the resource is authenticated using Entra ID. [see GitHub issue 49064](https://github.com/Azure/azure-sdk-for-net/issues/49064)
21+
* Fix dataset uploading datasets.
1122

1223
### Other Changes
1324

sdk/ai/Azure.AI.Projects/README.md

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,15 @@ The code below assumes `ModelDeploymentName` (a string) is defined. It's the dep
159159

160160
You can update the `connectionName` with one of the connections in your Foundry project, and you can update the `apiVersion` value with one found in the "Data plane - inference" row [in this table](https://learn.microsoft.com/azure/ai-services/openai/reference#api-specs).
161161

162-
```C# Snippet:AI_Projects_AzureOpenAISync
162+
```C# Snippet:AI_Projects_AzureOpenAIChatSync
163163
var endpoint = System.Environment.GetEnvironmentVariable("PROJECT_ENDPOINT");
164164
var modelDeploymentName = System.Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME");
165+
var connectionName = System.Environment.GetEnvironmentVariable("CONNECTION_NAME");
166+
Console.WriteLine("Create the Azure OpenAI chat client");
165167
AIProjectClient projectClient = new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential());
166-
ChatClient chatClient = projectClient.GetAzureOpenAIChatClient(deploymentName: modelDeploymentName, connectionName: null, apiVersion: null);
168+
ChatClient chatClient = projectClient.GetAzureOpenAIChatClient(deploymentName: modelDeploymentName, connectionName: connectionName, apiVersion: null);
167169

170+
Console.WriteLine("Complete a chat");
168171
ChatCompletion result = chatClient.CompleteChat("List all the rainbow colors");
169172
Console.WriteLine(result.Content[0].Text);
170173
```
@@ -176,10 +179,17 @@ Your Azure AI Foundry project may have one or more AI models deployed that suppo
176179
The code below assumes `ModelDeploymentName` (a string) is defined. It's the deployment name of an AI model in your Foundry Project, or a connected Azure OpenAI resource. As shown in the "Models + endpoints" tab, under the "Name" column.
177180

178181
```C# Snippet:AI_Projects_ChatClientSync
179-
var endpoint = System.Environment.GetEnvironmentVariable("PROJECT_ENDPOINT");
182+
var projectEndpoint = new Uri(System.Environment.GetEnvironmentVariable("PROJECT_ENDPOINT"));
180183
var modelDeploymentName = System.Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME");
181-
AIProjectClient client = new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential());
182-
ChatCompletionsClient chatClient = client.GetChatCompletionsClient();
184+
var inferenceEndpoint = $"{projectEndpoint.GetLeftPart(UriPartial.Authority)}/models";
185+
186+
AzureAIInferenceClientOptions clientOptions = new AzureAIInferenceClientOptions();
187+
188+
var credential = new DefaultAzureCredential();
189+
BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(credential, new string[] { "https://ai.azure.com/.default" });
190+
clientOptions.AddPolicy(tokenPolicy, HttpPipelinePosition.PerRetry);
191+
192+
ChatCompletionsClient chatClient = new ChatCompletionsClient(new Uri(inferenceEndpoint), credential, clientOptions);
183193

184194
var requestOptions = new ChatCompletionsOptions()
185195
{
@@ -203,22 +213,21 @@ var endpoint = System.Environment.GetEnvironmentVariable("PROJECT_ENDPOINT");
203213
var modelDeploymentName = System.Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME");
204214
var modelPublisher = System.Environment.GetEnvironmentVariable("MODEL_PUBLISHER");
205215
AIProjectClient projectClient = new(new Uri(endpoint), new DefaultAzureCredential());
206-
Deployments deployments = projectClient.GetDeploymentsClient();
207216

208217
Console.WriteLine("List all deployments:");
209-
foreach (var deployment in deployments.GetDeployments())
218+
foreach (AIDeployment deployment in projectClient.Deployments.GetDeployments())
210219
{
211220
Console.WriteLine(deployment);
212221
}
213222

214223
Console.WriteLine($"List all deployments by the model publisher `{modelPublisher}`:");
215-
foreach (var deployment in deployments.GetDeployments(modelPublisher: modelPublisher))
224+
foreach (AIDeployment deployment in projectClient.Deployments.GetDeployments(modelPublisher: modelPublisher))
216225
{
217226
Console.WriteLine(deployment);
218227
}
219228

220-
Console.WriteLine($"Get a single deployment named `{modelDeploymentName}`:");
221-
var deploymentDetails = deployments.GetDeployment(modelDeploymentName);
229+
Console.WriteLine($"Get a single model deployment named `{modelDeploymentName}`:");
230+
ModelDeployment deploymentDetails = projectClient.Deployments.GetModelDeployment(modelDeploymentName);
222231
Console.WriteLine(deploymentDetails);
223232
```
224233

@@ -230,35 +239,34 @@ The code below shows some Connection operations, which allow you to enumerate th
230239
var endpoint = Environment.GetEnvironmentVariable("PROJECT_ENDPOINT");
231240
var connectionName = Environment.GetEnvironmentVariable("CONNECTION_NAME");
232241
AIProjectClient projectClient = new(new Uri(endpoint), new DefaultAzureCredential());
233-
Connections connectionsClient = projectClient.GetConnectionsClient();
234242

235243
Console.WriteLine("List the properties of all connections:");
236-
foreach (var connection in connectionsClient.GetConnections())
244+
foreach (ConnectionProperties connection in projectClient.Connections.GetConnections())
237245
{
238246
Console.WriteLine(connection);
239-
Console.Write(connection.Name);
247+
Console.WriteLine(connection.Name);
240248
}
241249

242250
Console.WriteLine("List the properties of all connections of a particular type (e.g., Azure OpenAI connections):");
243-
foreach (var connection in connectionsClient.GetConnections(connectionType: ConnectionType.AzureOpenAI))
251+
foreach (ConnectionProperties connection in projectClient.Connections.GetConnections(connectionType: ConnectionType.AzureOpenAI))
244252
{
245253
Console.WriteLine(connection);
246254
}
247255

248256
Console.WriteLine($"Get the properties of a connection named `{connectionName}`:");
249-
var specificConnection = connectionsClient.Get(connectionName, includeCredentials: false);
257+
ConnectionProperties specificConnection = projectClient.Connections.Get(connectionName, includeCredentials: false);
250258
Console.WriteLine(specificConnection);
251259

252260
Console.WriteLine("Get the properties of a connection with credentials:");
253-
var specificConnectionCredentials = connectionsClient.Get(connectionName, includeCredentials: true);
261+
ConnectionProperties specificConnectionCredentials = projectClient.Connections.Get(connectionName, includeCredentials: true);
254262
Console.WriteLine(specificConnectionCredentials);
255263

256264
Console.WriteLine($"Get the properties of the default connection:");
257-
var defaultConnection = connectionsClient.GetDefault(includeCredentials: false);
265+
ConnectionProperties defaultConnection = projectClient.Connections.GetDefault(includeCredentials: false);
258266
Console.WriteLine(defaultConnection);
259267

260268
Console.WriteLine($"Get the properties of the default connection with credentials:");
261-
var defaultConnectionCredentials = connectionsClient.GetDefault(includeCredentials: true);
269+
ConnectionProperties defaultConnectionCredentials = projectClient.Connections.GetDefault(includeCredentials: true);
262270
Console.WriteLine(defaultConnectionCredentials);
263271
```
264272

@@ -268,45 +276,57 @@ The code below shows some Dataset operations. Full samples can be found under th
268276

269277
```C# Snippet:AI_Projects_DatasetsExampleSync
270278
var endpoint = System.Environment.GetEnvironmentVariable("PROJECT_ENDPOINT");
279+
var connectionName = Environment.GetEnvironmentVariable("CONNECTION_NAME");
271280
var datasetName = System.Environment.GetEnvironmentVariable("DATASET_NAME");
281+
var datasetVersion1 = System.Environment.GetEnvironmentVariable("DATASET_VERSION_1") ?? "1.0";
282+
var datasetVersion2 = System.Environment.GetEnvironmentVariable("DATASET_VERSION_2") ?? "2.0";
283+
var filePath = System.Environment.GetEnvironmentVariable("SAMPLE_FILE_PATH") ?? "sample_folder/sample_file1.txt";
284+
var folderPath = System.Environment.GetEnvironmentVariable("SAMPLE_FOLDER_PATH") ?? "sample_folder";
272285
AIProjectClient projectClient = new(new Uri(endpoint), new DefaultAzureCredential());
273-
Datasets datasets = projectClient.GetDatasetsClient();
274286

275-
Console.WriteLine("Uploading a single file to create Dataset version '1'...");
276-
var datasetResponse = datasets.UploadFile(
287+
Console.WriteLine($"Uploading a single file to create Dataset version {datasetVersion1}:");
288+
FileDatasetVersion fileDataset = projectClient.Datasets.UploadFile(
277289
name: datasetName,
278-
version: "1",
279-
filePath: "sample_folder/sample_file1.txt"
290+
version: datasetVersion1,
291+
filePath: filePath,
292+
connectionName: connectionName
280293
);
281-
Console.WriteLine(datasetResponse);
294+
Console.WriteLine(fileDataset);
282295

283-
Console.WriteLine("Uploading folder to create Dataset version '2'...");
284-
datasetResponse = datasets.UploadFolder(
296+
Console.WriteLine($"Uploading folder to create Dataset version {datasetVersion2}:");
297+
FolderDatasetVersion folderDataset = projectClient.Datasets.UploadFolder(
285298
name: datasetName,
286-
version: "2",
287-
folderPath: "sample_folder"
299+
version: datasetVersion2,
300+
folderPath: folderPath,
301+
connectionName: connectionName,
302+
filePattern: new Regex(".*\\.txt")
288303
);
289-
Console.WriteLine(datasetResponse);
304+
Console.WriteLine(folderDataset);
290305

291-
Console.WriteLine("Retrieving Dataset version '1'...");
292-
DatasetVersion dataset = datasets.GetDataset(datasetName, "1");
306+
Console.WriteLine($"Retrieving Dataset version {datasetVersion1}:");
307+
DatasetVersion dataset = projectClient.Datasets.GetDataset(datasetName, datasetVersion1);
293308
Console.WriteLine(dataset);
294309

310+
Console.WriteLine($"Retrieving credentials of Dataset {datasetName} version {datasetVersion1}:");
311+
AssetCredentialResponse credentials = projectClient.Datasets.GetCredentials(datasetName, datasetVersion1);
312+
Console.WriteLine(credentials);
313+
295314
Console.WriteLine($"Listing all versions for Dataset '{datasetName}':");
296-
foreach (var ds in datasets.GetVersions(datasetName))
315+
foreach (DatasetVersion ds in projectClient.Datasets.GetVersions(datasetName))
297316
{
298317
Console.WriteLine(ds);
318+
Console.WriteLine(ds.Version);
299319
}
300320

301321
Console.WriteLine($"Listing latest versions for all datasets:");
302-
foreach (var ds in datasets.GetDatasetVersions())
322+
foreach (DatasetVersion ds in projectClient.Datasets.GetDatasetVersions())
303323
{
304324
Console.WriteLine(ds);
305325
}
306326

307-
Console.WriteLine("Deleting Dataset versions '1' and '2'...");
308-
datasets.Delete(datasetName, "1");
309-
datasets.Delete(datasetName, "2");
327+
Console.WriteLine($"Deleting Dataset versions {datasetVersion1} and {datasetVersion2}:");
328+
projectClient.Datasets.Delete(datasetName, datasetVersion1);
329+
projectClient.Datasets.Delete(datasetName, datasetVersion2);
310330
```
311331

312332
### Indexes operations
@@ -320,44 +340,42 @@ var indexVersion = Environment.GetEnvironmentVariable("INDEX_VERSION") ?? "1.0";
320340
var aiSearchConnectionName = Environment.GetEnvironmentVariable("AI_SEARCH_CONNECTION_NAME") ?? "my-ai-search-connection-name";
321341
var aiSearchIndexName = Environment.GetEnvironmentVariable("AI_SEARCH_INDEX_NAME") ?? "my-ai-search-index-name";
322342
AIProjectClient projectClient = new(new Uri(endpoint), new DefaultAzureCredential());
323-
Indexes indexesClient = projectClient.GetIndexesClient();
324343

325344
RequestContent content = RequestContent.Create(new
326345
{
327346
connectionName = aiSearchConnectionName,
328347
indexName = aiSearchIndexName,
329-
indexVersion = indexVersion,
330348
type = "AzureSearch",
331349
description = "Sample Index for testing",
332350
displayName = "Sample Index"
333351
});
334352

335353
Console.WriteLine($"Create an Index named `{indexName}` referencing an existing AI Search resource:");
336-
var index = indexesClient.CreateOrUpdate(
354+
var index = projectClient.Indexes.CreateOrUpdate(
337355
name: indexName,
338356
version: indexVersion,
339357
content: content
340358
);
341359
Console.WriteLine(index);
342360

343361
Console.WriteLine($"Get an existing Index named `{indexName}`, version `{indexVersion}`:");
344-
var retrievedIndex = indexesClient.GetIndex(name: indexName, version: indexVersion);
362+
DatasetIndex retrievedIndex = projectClient.Indexes.GetIndex(name: indexName, version: indexVersion);
345363
Console.WriteLine(retrievedIndex);
346364

347365
Console.WriteLine($"Listing all versions of the Index named `{indexName}`:");
348-
foreach (var version in indexesClient.GetVersions(name: indexName))
366+
foreach (DatasetIndex version in projectClient.Indexes.GetVersions(name: indexName))
349367
{
350368
Console.WriteLine(version);
351369
}
352370

353371
Console.WriteLine($"Listing all Indices:");
354-
foreach (var version in indexesClient.GetIndices())
372+
foreach (DatasetIndex version in projectClient.Indexes.GetIndices())
355373
{
356374
Console.WriteLine(version);
357375
}
358376

359377
Console.WriteLine("Delete the Index version created above:");
360-
indexesClient.Delete(name: indexName, version: indexVersion);
378+
projectClient.Indexes.Delete(name: indexName, version: indexVersion);
361379
```
362380

363381
## Troubleshooting
@@ -367,7 +385,7 @@ Any operation that fails will throw a [RequestFailedException][RequestFailedExce
367385
```C# Snippet:AI_Projects_Readme_Troubleshooting
368386
try
369387
{
370-
projectClient.GetDatasetsClient().GetDataset("non-existent-dataset-name", "non-existent-dataset-version");
388+
projectClient.Datasets.GetDataset("non-existent-dataset-name", "non-existent-dataset-version");
371389
}
372390
catch (RequestFailedException ex) when (ex.Status == 404)
373391
{

0 commit comments

Comments
 (0)