Skip to content

Commit ae4cd69

Browse files
committed
update samples for generated code
1 parent 435ea8f commit ae4cd69

File tree

7 files changed

+116
-55
lines changed

7 files changed

+116
-55
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Threading.Tasks;
8+
using Azure.Storage.Blobs;
9+
using Azure.Core;
10+
using Azure.Core.Pipeline;
11+
12+
namespace Azure.AI.Projects
13+
{
14+
public partial class Connections
15+
{
16+
/// <summary>
17+
/// Get a connection by name.
18+
/// </summary>
19+
/// <param name="connectionName">The name of the connection. Required.</param>
20+
/// <param name="includeCredentials">Whether to include credentials in the response. Default is false.</param>
21+
/// <returns>A <see cref="Connection"/> object.</returns>
22+
/// <exception cref="RequestFailedException">Thrown when the request fails.</exception>
23+
public Connection Get(string connectionName, bool includeCredentials = false)
24+
{
25+
if (string.IsNullOrWhiteSpace(connectionName))
26+
{
27+
throw new ArgumentException("Connection name cannot be null or empty.", nameof(connectionName));
28+
}
29+
30+
// Use the instance method instead of incorrectly calling it as static
31+
if (includeCredentials)
32+
{
33+
return GetWithCredentials(connectionName);
34+
}
35+
36+
return GetConnection(connectionName);
37+
}
38+
39+
/// <summary>
40+
/// Get a connection by name.
41+
/// </summary>
42+
/// <param name="connectionName">The name of the connection. Required.</param>
43+
/// <param name="includeCredentials">Whether to include credentials in the response. Default is false.</param>
44+
/// <returns>A <see cref="Connection"/> object.</returns>
45+
/// <exception cref="RequestFailedException">Thrown when the request fails.</exception>
46+
public async Task<Response<Connection>> GetAsync(string connectionName, bool includeCredentials = false)
47+
{
48+
if (string.IsNullOrWhiteSpace(connectionName))
49+
{
50+
throw new ArgumentException("Connection name cannot be null or empty.", nameof(connectionName));
51+
}
52+
53+
// Use the instance method instead of incorrectly calling it as static
54+
if (includeCredentials)
55+
{
56+
return await GetWithCredentialsAsync(connectionName).ConfigureAwait(false);
57+
}
58+
59+
return await GetConnectionAsync(connectionName).ConfigureAwait(false);
60+
}
61+
}
62+
}

sdk/ai/Azure.AI.Projects/src/Custom/Datasets/Datasets.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Azure.Storage.Blobs;
99
using Azure.Core;
1010
using Azure.Core.Pipeline;
11-
using Azure.AI.Projects;
11+
using System.Runtime.InteropServices.ComTypes;
1212

1313
namespace Azure.AI.Projects
1414
{
@@ -19,10 +19,10 @@ public partial class Datasets
1919
/// </summary>
2020
private (BlobContainerClient ContainerClient, string OutputVersion) CreateDatasetAndGetContainerClient(string name, string inputVersion)
2121
{
22-
var pendingUploadResponse = StartPendingUploadVersion(
22+
var pendingUploadResponse = PendingUpload(
2323
name,
2424
inputVersion,
25-
new PendingUploadRequest(null, null, PendingUploadType.TemporaryBlobReference, null)
25+
new PendingUploadRequest(null, null, PendingUploadType.BlobReference, null)
2626
);
2727

2828
string outputVersion = inputVersion;
@@ -34,14 +34,14 @@ public partial class Datasets
3434
// throw new InvalidOperationException("Invalid blob reference for consumption.");
3535
//}
3636

37-
var containerClient = new BlobContainerClient(new Uri(pendingUploadResponse.Value.BlobReferenceForConsumption.BlobUri));
37+
var containerClient = new BlobContainerClient(new Uri(pendingUploadResponse.Value.BlobReference.BlobUri));
3838
return (containerClient, outputVersion);
3939
}
4040

4141
/// <summary>
4242
/// Uploads a file to blob storage and creates a dataset that references this file.
4343
/// </summary>
44-
public DatasetVersion UploadFileAndCreate(string name, string version, string filePath)
44+
public Response UploadFile(string name, string version, string filePath)
4545
{
4646
if (!File.Exists(filePath))
4747
{
@@ -57,22 +57,20 @@ public DatasetVersion UploadFileAndCreate(string name, string version, string fi
5757
var blobClient = containerClient.GetBlobClient(blobName);
5858
blobClient.Upload(fileStream);
5959

60-
return CreateVersion(
60+
RequestContent content = RequestContent.Create(new FileDatasetVersion(dataUri: blobClient.Uri.AbsoluteUri));
61+
62+
return CreateOrUpdate(
6163
name,
6264
outputVersion,
63-
new FileDatasetVersion
64-
{
65-
DatasetUri = blobClient.Uri.AbsoluteUri,
66-
Type = DatasetType.UriFile
67-
}
65+
content
6866
);
6967
}
7068
}
7169

7270
/// <summary>
7371
/// Uploads all files in a folder to blob storage and creates a dataset that references this folder.
7472
/// </summary>
75-
public DatasetVersion UploadFolderAndCreate(string name, string version, string folderPath)
73+
public Response UploadFolder(string name, string version, string folderPath)
7674
{
7775
if (!Directory.Exists(folderPath))
7876
{
@@ -99,14 +97,11 @@ public DatasetVersion UploadFolderAndCreate(string name, string version, string
9997
throw new ArgumentException("The provided folder is empty.");
10098
}
10199

102-
return CreateVersion(
100+
RequestContent content = RequestContent.Create(new FolderDatasetVersion(dataUri: containerClient.Uri.AbsoluteUri));
101+
return CreateOrUpdate(
103102
name,
104103
outputVersion,
105-
new FolderDatasetVersion
106-
{
107-
DatasetUri = containerClient.Uri.AbsoluteUri,
108-
Type = DatasetType.UriFolder
109-
}
104+
content
110105
);
111106
}
112107
public static string GetRelativePath(string folderPath, string filePath)

sdk/ai/Azure.AI.Projects/src/Custom/Evaluations/EvaluatorIDs.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
using System;
77
using System.Collections.Generic;
8-
using Azure.AI.OpenAI;
98

109
namespace Azure.AI.Projects
1110
{

sdk/ai/Azure.AI.Projects/tests/Samples/Connections/Sample_Connections.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public void ConnectionsExample()
4242
}
4343

4444
Console.WriteLine($"Get the properties of a connection named `{connectionName}`:");
45-
var specificConnection = connectionsClient.GetConnection(connectionName);
45+
var specificConnection = connectionsClient.Get(connectionName, includeCredentials: false);
4646
Console.WriteLine(specificConnection);
4747

4848
Console.WriteLine("Get the properties of a connection with credentials:");
49-
var specificConnectionCredentials = connectionsClient.GetWithCredentials(connectionName);
49+
var specificConnectionCredentials = connectionsClient.Get(connectionName, includeCredentials: true);
5050
Console.WriteLine(specificConnectionCredentials);
5151

5252
#endregion
@@ -81,11 +81,11 @@ public async Task ConnectionsExampleAsync()
8181
}
8282

8383
Console.WriteLine($"Get the properties of a connection named `{connectionName}`:");
84-
var specificConnection = await connectionsClient.GetConnectionAsync(connectionName);
84+
var specificConnection = await connectionsClient.GetAsync(connectionName, includeCredentials: false);
8585
Console.WriteLine(specificConnection);
8686

8787
Console.WriteLine("Get the properties of a connection with credentials:");
88-
var specificConnectionCredentials = await connectionsClient.GetWithCredentialsAsync(connectionName);
88+
var specificConnectionCredentials = await connectionsClient.GetAsync(connectionName, includeCredentials: true);
8989
Console.WriteLine(specificConnectionCredentials);
9090

9191
#endregion

sdk/ai/Azure.AI.Projects/tests/Samples/Datasets/Sample_Datasets.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,38 @@ public void DatasetsExample()
3333
Datasets datasets = projectClient.GetDatasetsClient();
3434

3535
Console.WriteLine("Uploading a single file to create Dataset version '1'...");
36-
var dataset = datasets.UploadFileAndCreate(
36+
var datasetResponse = datasets.UploadFile(
3737
name: datasetName,
3838
version: "1",
3939
filePath: "sample_folder/sample_file1.txt"
4040
);
41-
Console.WriteLine(dataset);
41+
Console.WriteLine(datasetResponse);
4242

4343
Console.WriteLine("Uploading folder to create Dataset version '2'...");
44-
dataset = datasets.UploadFolderAndCreate(
44+
datasetResponse = datasets.UploadFolder(
4545
name: datasetName,
4646
version: "2",
4747
folderPath: "sample_folder"
4848
);
49-
Console.WriteLine(dataset.DatasetUri);
49+
Console.WriteLine(datasetResponse);
5050

5151
Console.WriteLine("Retrieving Dataset version '1'...");
52-
dataset = datasets.GetVersion(datasetName, "1");
53-
Console.WriteLine(dataset.DatasetUri);
52+
DatasetVersion dataset = datasets.GetDataset(datasetName, "1");
53+
Console.WriteLine(dataset);
5454

5555
Console.WriteLine($"Listing all versions for Dataset '{datasetName}':");
5656
foreach (var ds in datasets.GetVersions(datasetName))
5757
{
58-
Console.WriteLine(ds.DatasetUri);
58+
Console.WriteLine(ds);
5959
}
6060

6161
Console.WriteLine("Retrieving Dataset version '1' credentials...");
6262
var credentials = datasets.GetCredentials(datasetName, "1", new GetCredentialsRequest());
6363
Console.WriteLine(credentials);
6464

6565
Console.WriteLine("Deleting Dataset versions '1' and '2'...");
66-
datasets.DeleteVersion(datasetName, "1");
67-
datasets.DeleteVersion(datasetName, "2");
66+
datasets.Delete(datasetName, "1");
67+
datasets.Delete(datasetName, "2");
6868
#endregion
6969
}
7070

@@ -84,38 +84,38 @@ public async void DatasetsExampleAsync()
8484
Datasets datasets = projectClient.GetDatasetsClient();
8585

8686
Console.WriteLine("Uploading a single file to create Dataset version '1'...");
87-
var dataset = datasets.UploadFileAndCreate(
87+
var datasetResponse = datasets.UploadFile(
8888
name: datasetName,
8989
version: "1",
9090
filePath: "sample_folder/sample_file1.txt"
9191
);
92-
Console.WriteLine(dataset);
92+
Console.WriteLine(datasetResponse);
9393

9494
Console.WriteLine("Uploading folder to create Dataset version '2'...");
95-
dataset = datasets.UploadFolderAndCreate(
95+
datasetResponse = datasets.UploadFolder(
9696
name: datasetName,
9797
version: "2",
9898
folderPath: "sample_folder"
9999
);
100-
Console.WriteLine(dataset.DatasetUri);
100+
Console.WriteLine(datasetResponse);
101101

102102
Console.WriteLine("Retrieving Dataset version '1'...");
103-
dataset = await datasets.GetVersionAsync(datasetName, "1");
104-
Console.WriteLine(dataset.DatasetUri);
103+
DatasetVersion dataset = await datasets.GetDatasetAsync(datasetName, "1");
104+
Console.WriteLine(dataset);
105105

106106
Console.WriteLine($"Listing all versions for Dataset '{datasetName}':");
107107
await foreach (var ds in datasets.GetVersionsAsync(datasetName))
108108
{
109-
Console.WriteLine(ds.DatasetUri);
109+
Console.WriteLine(ds);
110110
}
111111

112112
Console.WriteLine("Retrieving Dataset version '1' credentials...");
113113
var credentials = await datasets.GetCredentialsAsync(datasetName, "1", new GetCredentialsRequest());
114114
Console.WriteLine(credentials);
115115

116116
Console.WriteLine("Deleting Dataset versions '1' and '2'...");
117-
await datasets.DeleteVersionAsync(datasetName, "1");
118-
await datasets.DeleteVersionAsync(datasetName, "2");
117+
await datasets.DeleteAsync(datasetName, "1");
118+
await datasets.DeleteAsync(datasetName, "2");
119119
#endregion
120120
}
121121
}

sdk/ai/Azure.AI.Projects/tests/Samples/Evaluation/Sample_Evaluation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void EvaluationsExampleSync()
5959
Console.WriteLine(evaluationResponse);
6060

6161
Console.WriteLine("Get evaluation");
62-
Evaluation getEvaluationResponse = evaluations.GetEvaluation(evaluationResponse.Id);
62+
Evaluation getEvaluationResponse = evaluations.GetEvaluation(evaluationResponse.Name);
6363
Console.WriteLine(getEvaluationResponse);
6464

6565
Console.WriteLine("List evaluations");
@@ -113,7 +113,7 @@ public async Task EvaluationsExampleAsync()
113113
Console.WriteLine(evaluationResponse);
114114

115115
Console.WriteLine("Get evaluation");
116-
Evaluation getEvaluationResponse = await evaluations.GetEvaluationAsync(evaluationResponse.Id);
116+
Evaluation getEvaluationResponse = await evaluations.GetEvaluationAsync(evaluationResponse.Name);
117117
Console.WriteLine(getEvaluationResponse);
118118

119119
Console.WriteLine("List evaluations");

sdk/ai/Azure.AI.Projects/tests/Samples/Indexes/Sample_Indexes.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Threading.Tasks;
88
using Azure.AI.Projects;
9+
using Azure.Core;
910
using Azure.Core.TestFramework;
1011
using NUnit.Framework;
1112

@@ -34,16 +35,26 @@ public void IndexesExample()
3435
AIProjectClient projectClient = new(new Uri(endpoint), new DefaultAzureCredential());
3536
Indexes indexesClient = projectClient.GetIndexesClient();
3637

38+
RequestContent content = RequestContent.Create(new
39+
{
40+
connectionName = aiSearchConnectionName,
41+
indexName = aiSearchIndexName,
42+
indexVersion = indexVersion,
43+
//indexType = IndexType.AzureSearch,
44+
description = "Sample Index for testing",
45+
displayName = "Sample Index"
46+
});
47+
3748
Console.WriteLine($"Create an Index named `{indexName}` referencing an existing AI Search resource:");
38-
var index = indexesClient.CreateVersion(
49+
var index = indexesClient.CreateOrUpdate(
3950
name: indexName,
4051
version: indexVersion,
41-
body: new AzureAISearchIndex(connectionName: aiSearchConnectionName, indexName: aiSearchIndexName)
42-
);
52+
content: content
53+
);
4354
Console.WriteLine(index);
4455

4556
Console.WriteLine($"Get an existing Index named `{indexName}`, version `{indexVersion}`:");
46-
var retrievedIndex = indexesClient.GetVersion(name: indexName, version: indexVersion);
57+
var retrievedIndex = indexesClient.GetIndex(name: indexName, version: indexVersion);
4758
Console.WriteLine(retrievedIndex);
4859

4960
Console.WriteLine($"Listing all versions of the Index named `{indexName}`:");
@@ -52,14 +63,8 @@ public void IndexesExample()
5263
Console.WriteLine(version);
5364
}
5465

55-
Console.WriteLine("List latest versions of all Indexes:");
56-
foreach (var latestIndex in indexesClient.GetLatests())
57-
{
58-
Console.WriteLine(latestIndex);
59-
}
60-
61-
Console.WriteLine("Delete the Index versions created above:");
62-
indexesClient.DeleteVersion(name: indexName, version: indexVersion);
66+
Console.WriteLine("Delete the Index version created above:");
67+
indexesClient.Delete(name: indexName, version: indexVersion);
6368
#endregion
6469
}
6570
}

0 commit comments

Comments
 (0)