Skip to content

Commit ef7b4d8

Browse files
Azure.AI.Projects tests and recordings (Azure#52235)
* initial tests * tests following guide * tests with recording and sanitation enabled * telemetry recording * update name changes * final test updates * update assets.json tag * update api * address comments, consolidate test framework * run scripts
1 parent d63913c commit ef7b4d8

17 files changed

+1475
-17
lines changed

sdk/ai/Azure.AI.Projects/api/Azure.AI.Projects.net8.0.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public AIProjectClient(System.Uri endpoint, System.ClientModel.AuthenticationTok
114114
public virtual Azure.AI.Projects.DeploymentsOperations GetDeploymentsOperationsClient() { throw null; }
115115
public virtual Azure.AI.Projects.Evaluations GetEvaluationsClient() { throw null; }
116116
public virtual Azure.AI.Projects.IndexesOperations GetIndexesOperationsClient() { throw null; }
117-
public OpenAI.OpenAIClient GetOpenAIClient(string? connectionName = null, string? apiVersion = null) { throw null; }
117+
public virtual OpenAI.OpenAIClient GetOpenAIClient(string? connectionName = null, string? apiVersion = null) { throw null; }
118118
public virtual Azure.AI.Projects.RedTeams GetRedTeamsClient() { throw null; }
119119
}
120120
public partial class AIProjectClientOptions : System.ClientModel.Primitives.ClientPipelineOptions
@@ -370,14 +370,14 @@ public partial class ConnectionsOperations
370370
{
371371
protected ConnectionsOperations() { }
372372
public System.ClientModel.Primitives.ClientPipeline Pipeline { get { throw null; } }
373-
public Azure.AI.Projects.ConnectionProperties GetConnection(string connectionName, bool includeCredentials = false, string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
374-
public System.Threading.Tasks.Task<System.ClientModel.ClientResult<Azure.AI.Projects.ConnectionProperties>> GetConnectionAsync(string connectionName, bool includeCredentials = false, string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
373+
public virtual Azure.AI.Projects.ConnectionProperties GetConnection(string connectionName, bool includeCredentials = false, string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
374+
public virtual System.Threading.Tasks.Task<System.ClientModel.ClientResult<Azure.AI.Projects.ConnectionProperties>> GetConnectionAsync(string connectionName, bool includeCredentials = false, string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
375375
public virtual System.ClientModel.CollectionResult<Azure.AI.Projects.ConnectionProperties> GetConnections(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool? defaultConnection = default(bool?), string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
376376
public virtual System.ClientModel.Primitives.CollectionResult GetConnections(string connectionType, bool? defaultConnection, string clientRequestId, System.ClientModel.Primitives.RequestOptions options) { throw null; }
377377
public virtual System.ClientModel.AsyncCollectionResult<Azure.AI.Projects.ConnectionProperties> GetConnectionsAsync(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool? defaultConnection = default(bool?), string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
378378
public virtual System.ClientModel.Primitives.AsyncCollectionResult GetConnectionsAsync(string connectionType, bool? defaultConnection, string clientRequestId, System.ClientModel.Primitives.RequestOptions options) { throw null; }
379-
public Azure.AI.Projects.ConnectionProperties GetDefaultConnection(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool includeCredentials = false) { throw null; }
380-
public System.Threading.Tasks.Task<Azure.AI.Projects.ConnectionProperties> GetDefaultConnectionAsync(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool includeCredentials = false) { throw null; }
379+
public virtual Azure.AI.Projects.ConnectionProperties GetDefaultConnection(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool includeCredentials = false) { throw null; }
380+
public virtual System.Threading.Tasks.Task<Azure.AI.Projects.ConnectionProperties> GetDefaultConnectionAsync(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool includeCredentials = false) { throw null; }
381381
}
382382
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
383383
public readonly partial struct ConnectionType : System.IEquatable<Azure.AI.Projects.ConnectionType>

sdk/ai/Azure.AI.Projects/api/Azure.AI.Projects.netstandard2.0.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public AIProjectClient(System.Uri endpoint, System.ClientModel.AuthenticationTok
114114
public virtual Azure.AI.Projects.DeploymentsOperations GetDeploymentsOperationsClient() { throw null; }
115115
public virtual Azure.AI.Projects.Evaluations GetEvaluationsClient() { throw null; }
116116
public virtual Azure.AI.Projects.IndexesOperations GetIndexesOperationsClient() { throw null; }
117-
public OpenAI.OpenAIClient GetOpenAIClient(string? connectionName = null, string? apiVersion = null) { throw null; }
117+
public virtual OpenAI.OpenAIClient GetOpenAIClient(string? connectionName = null, string? apiVersion = null) { throw null; }
118118
public virtual Azure.AI.Projects.RedTeams GetRedTeamsClient() { throw null; }
119119
}
120120
public partial class AIProjectClientOptions : System.ClientModel.Primitives.ClientPipelineOptions
@@ -370,14 +370,14 @@ public partial class ConnectionsOperations
370370
{
371371
protected ConnectionsOperations() { }
372372
public System.ClientModel.Primitives.ClientPipeline Pipeline { get { throw null; } }
373-
public Azure.AI.Projects.ConnectionProperties GetConnection(string connectionName, bool includeCredentials = false, string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
374-
public System.Threading.Tasks.Task<System.ClientModel.ClientResult<Azure.AI.Projects.ConnectionProperties>> GetConnectionAsync(string connectionName, bool includeCredentials = false, string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
373+
public virtual Azure.AI.Projects.ConnectionProperties GetConnection(string connectionName, bool includeCredentials = false, string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
374+
public virtual System.Threading.Tasks.Task<System.ClientModel.ClientResult<Azure.AI.Projects.ConnectionProperties>> GetConnectionAsync(string connectionName, bool includeCredentials = false, string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
375375
public virtual System.ClientModel.CollectionResult<Azure.AI.Projects.ConnectionProperties> GetConnections(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool? defaultConnection = default(bool?), string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
376376
public virtual System.ClientModel.Primitives.CollectionResult GetConnections(string connectionType, bool? defaultConnection, string clientRequestId, System.ClientModel.Primitives.RequestOptions options) { throw null; }
377377
public virtual System.ClientModel.AsyncCollectionResult<Azure.AI.Projects.ConnectionProperties> GetConnectionsAsync(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool? defaultConnection = default(bool?), string clientRequestId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
378378
public virtual System.ClientModel.Primitives.AsyncCollectionResult GetConnectionsAsync(string connectionType, bool? defaultConnection, string clientRequestId, System.ClientModel.Primitives.RequestOptions options) { throw null; }
379-
public Azure.AI.Projects.ConnectionProperties GetDefaultConnection(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool includeCredentials = false) { throw null; }
380-
public System.Threading.Tasks.Task<Azure.AI.Projects.ConnectionProperties> GetDefaultConnectionAsync(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool includeCredentials = false) { throw null; }
379+
public virtual Azure.AI.Projects.ConnectionProperties GetDefaultConnection(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool includeCredentials = false) { throw null; }
380+
public virtual System.Threading.Tasks.Task<Azure.AI.Projects.ConnectionProperties> GetDefaultConnectionAsync(Azure.AI.Projects.ConnectionType? connectionType = default(Azure.AI.Projects.ConnectionType?), bool includeCredentials = false) { throw null; }
381381
}
382382
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
383383
public readonly partial struct ConnectionType : System.IEquatable<Azure.AI.Projects.ConnectionType>

sdk/ai/Azure.AI.Projects/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "net",
44
"TagPrefix": "net/ai/Azure.AI.Projects",
5-
"Tag": "net/ai/Azure.AI.Projects_2d64ec531c"
5+
"Tag": "net/ai/Azure.AI.Projects_7e48fa872a"
66
}

sdk/ai/Azure.AI.Projects/src/Custom/Connections/ConnectionsOperations.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public partial class ConnectionsOperations
1919
/// <param name="cancellationToken"> The cancellation token that can be used to cancel the operation. </param>
2020
/// <returns>A <see cref="ConnectionProperties"/> object.</returns>
2121
/// <exception cref="RequestFailedException">Thrown when the request fails.</exception>
22-
public ConnectionProperties GetConnection(string connectionName, bool includeCredentials = false, string clientRequestId = default, CancellationToken cancellationToken = default)
22+
public virtual ConnectionProperties GetConnection(string connectionName, bool includeCredentials = false, string clientRequestId = default, CancellationToken cancellationToken = default)
2323
{
2424
if (string.IsNullOrWhiteSpace(connectionName))
2525
{
@@ -44,7 +44,7 @@ public ConnectionProperties GetConnection(string connectionName, bool includeCre
4444
/// <param name="cancellationToken"> The cancellation token that can be used to cancel the operation. </param>
4545
/// <returns>A <see cref="ConnectionProperties"/> object.</returns>
4646
/// <exception cref="RequestFailedException">Thrown when the request fails.</exception>
47-
public async Task<ClientResult<ConnectionProperties>> GetConnectionAsync(string connectionName, bool includeCredentials = false, string clientRequestId = default, CancellationToken cancellationToken = default)
47+
public virtual async Task<ClientResult<ConnectionProperties>> GetConnectionAsync(string connectionName, bool includeCredentials = false, string clientRequestId = default, CancellationToken cancellationToken = default)
4848
{
4949
if (string.IsNullOrWhiteSpace(connectionName))
5050
{
@@ -67,7 +67,7 @@ public async Task<ClientResult<ConnectionProperties>> GetConnectionAsync(string
6767
/// <param name="includeCredentials">Whether to include credentials in the response. Default is false.</param>
6868
/// <returns>A <see cref="ConnectionProperties"/> object.</returns>
6969
/// <exception cref="RequestFailedException">Thrown when the request fails.</exception>
70-
public ConnectionProperties GetDefaultConnection(ConnectionType? connectionType = null, bool includeCredentials = false)
70+
public virtual ConnectionProperties GetDefaultConnection(ConnectionType? connectionType = null, bool includeCredentials = false)
7171
{
7272
foreach (var connection in GetConnections(connectionType))
7373
{
@@ -86,7 +86,7 @@ public ConnectionProperties GetDefaultConnection(ConnectionType? connectionType
8686
/// <param name="includeCredentials">Whether to include credentials in the response. Default is false.</param>
8787
/// <returns>A <see cref="ConnectionProperties"/> object.</returns>
8888
/// <exception cref="RequestFailedException">Thrown when the request fails.</exception>
89-
public async Task<ConnectionProperties> GetDefaultConnectionAsync(ConnectionType? connectionType = null, bool includeCredentials = false)
89+
public virtual async Task<ConnectionProperties> GetDefaultConnectionAsync(ConnectionType? connectionType = null, bool includeCredentials = false)
9090
{
9191
await foreach (var connection in GetConnectionsAsync(connectionType).ConfigureAwait(false))
9292
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class AIProjectClient : ClientConnectionProvider
2727
/// <param name="connectionName"></param>
2828
/// <param name="apiVersion"></param>
2929
/// <returns></returns>
30-
public OpenAIClient GetOpenAIClient(string? connectionName = null, string? apiVersion = null)
30+
public virtual OpenAIClient GetOpenAIClient(string? connectionName = null, string? apiVersion = null)
3131
{
3232
AzureOpenAIClientKey openAIClientKey = new();
3333

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
#nullable disable
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
using Azure.AI.Agents.Persistent;
12+
using Azure.Identity;
13+
using Azure.Core.TestFramework;
14+
using NUnit.Framework;
15+
using Azure.AI.Projects.Tests.Utils;
16+
17+
namespace Azure.AI.Projects.Tests;
18+
19+
public class AIAgentsTest : ProjectsClientTestBase
20+
{
21+
public AIAgentsTest(bool isAsync) : base(isAsync) //, RecordedTestMode.Record)
22+
{
23+
}
24+
25+
[TestCase]
26+
[RecordedTest]
27+
[Ignore("Agents API calls are not recorded")]
28+
public async Task AgentsTest()
29+
{
30+
var modelDeploymentName = TestEnvironment.MODELDEPLOYMENTNAME;
31+
32+
AIProjectClient projectClient = GetTestClient();
33+
PersistentAgentsClient agentsClient = projectClient.GetPersistentAgentsClient();
34+
35+
Console.WriteLine("Create an agent with a model deployment");
36+
PersistentAgent agent = await agentsClient.Administration.CreateAgentAsync(
37+
model: modelDeploymentName,
38+
name: "Math Tutor",
39+
instructions: "You are a personal math tutor. Write and run code to answer math questions."
40+
);
41+
Assert.NotNull(agent.Id);
42+
Assert.AreEqual(agent.Model, modelDeploymentName);
43+
Assert.AreEqual(agent.Name, "Math Tutor");
44+
Assert.AreEqual(agent.Instructions, "You are a personal math tutor. Write and run code to answer math questions.");
45+
46+
await agentsClient.Administration.DeleteAgentAsync(agentId: agent.Id);
47+
}
48+
}

sdk/ai/Azure.AI.Projects/tests/AIProjectsTestEnvironment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Azure.AI.Projects.Tests
77
{
88
public class AIProjectsTestEnvironment : TestEnvironment
99
{
10-
public string PROJECTENDPOINT => GetRecordedVariable("PROJECT_ENDPOINT");
10+
public string PROJECTENDPOINT => GetRecordedVariable("PROJECT_ENDPOINT", options => options.IsSecret("https://sanitized-host.services.ai.azure.com/api/projects/sanitized-project"));
1111
public string DATASETNAME => GetRecordedVariable("DATASET_NAME");
1212
public string DATASETVERSION1 => GetRecordedVariable("DATASET_VERSION_1");
1313
public string DATASETVERSION2 => GetRecordedVariable("DATASET_VERSION_2");
@@ -19,6 +19,7 @@ public class AIProjectsTestEnvironment : TestEnvironment
1919
public string AISEARCHCONNECTIONNAME => GetRecordedVariable("AI_SEARCH_CONNECTION_NAME");
2020
public string AISEARCHINDEXNAME => GetRecordedVariable("AI_SEARCH_INDEX_NAME");
2121
public string CONNECTIONNAME => GetRecordedVariable("CONNECTION_NAME");
22+
public string CONNECTIONTYPE => GetRecordedVariable("CONNECTION_TYPE");
2223
public string AOAICONNECTIONNAME => GetRecordedVariable("AOAI_CONNECTION_NAME");
2324
public string TESTIMAGEPNGINPUTPATH => GetRecordedVariable("TEST_IMAGE_PNG_INPUT_PATH");
2425
public string SAMPLEFILEPATH => GetRecordedVariable("SAMPLE_FILE_PATH");
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+
#nullable disable
5+
6+
using System;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
using Azure.AI.OpenAI;
10+
using Azure.Core.TestFramework;
11+
using NUnit.Framework;
12+
using OpenAI.Chat;
13+
using Azure.Identity;
14+
using Azure.AI.Projects.Tests.Utils;
15+
16+
namespace Azure.AI.Projects.Tests;
17+
18+
public class AzureOpenAI_ChatTest : ProjectsClientTestBase
19+
{
20+
public AzureOpenAI_ChatTest(bool isAsync) : base(isAsync)//, RecordedTestMode.Record)
21+
{
22+
}
23+
24+
[TestCase]
25+
[RecordedTest]
26+
[Ignore("Calls to AzureOpenAIClient are not recorded yet")]
27+
public async Task AzureOpenAI_ChatTestAsync()
28+
{
29+
var modelDeploymentName = TestEnvironment.MODELDEPLOYMENTNAME;
30+
var connectionName = TestEnvironment.AOAICONNECTIONNAME;
31+
32+
Console.WriteLine("Create the Azure OpenAI chat client");
33+
AIProjectClient projectClient = GetTestClient();
34+
AzureOpenAIClient azureOpenAIClient = (AzureOpenAIClient)projectClient.GetOpenAIClient(connectionName: connectionName, apiVersion: null);
35+
ChatClient chatClient = azureOpenAIClient.GetChatClient(deploymentName: modelDeploymentName);
36+
37+
Console.WriteLine("Complete a chat");
38+
ChatCompletion result = await chatClient.CompleteChatAsync("How many feet are in a mile?");
39+
Console.WriteLine(result.Content[0].Text);
40+
var contains = new[] { "5280", "5,280", "five thousand two hundred eighty", "five thousand two hundred and eighty" };
41+
Assert.That(contains.Any(item => result.Content[0].Text.Contains(item)), "The response should contain the number of feet in a mile.");
42+
}
43+
44+
[TestCase]
45+
[RecordedTest]
46+
[Ignore("Calls to AzureOpenAIClient are not recorded yet")]
47+
public async Task AzureOpenAI_ChatTest_NoConnection()
48+
{
49+
var modelDeploymentName = TestEnvironment.MODELDEPLOYMENTNAME;
50+
51+
Console.WriteLine("Create the Azure OpenAI chat client");
52+
AIProjectClient projectClient = GetTestClient();
53+
AzureOpenAIClient azureOpenAIClient = (AzureOpenAIClient)projectClient.GetOpenAIClient(connectionName: null, apiVersion: null);
54+
ChatClient chatClient = azureOpenAIClient.GetChatClient(deploymentName: modelDeploymentName);
55+
56+
Console.WriteLine("Complete a chat");
57+
ChatCompletion result = await chatClient.CompleteChatAsync("How many feet are in a mile?");
58+
Console.WriteLine(result.Content[0].Text);
59+
var contains = new[] { "5280", "5,280", "five thousand two hundred eighty", "five thousand two hundred and eighty" };
60+
Assert.That(contains.Any(item => result.Content[0].Text.Contains(item)), "The response should contain the number of feet in a mile.");
61+
}
62+
}

0 commit comments

Comments
 (0)