Skip to content

Commit

Permalink
Support multiple deployments per cognitive service (dotnet#3448)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros authored and eerhardt committed Apr 29, 2024
1 parent 6c8ddfa commit fb8ba84
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public static IResourceBuilder<AzureOpenAIResource> AddAzureOpenAI(this IDistrib
var resource = (AzureOpenAIResource)construct.Resource;
CognitiveServicesAccountDeployment? dependency = null;
var cdkDeployments = new List<CognitiveServicesAccountDeployment>();
foreach (var deployment in resource.Deployments)
{
Expand All @@ -65,6 +67,17 @@ public static IResourceBuilder<AzureOpenAIResource> AddAzureOpenAI(this IDistrib
cdkDeployment.AssignProperty(x => x.Sku.Name, $"'{deployment.SkuName}'");
cdkDeployment.AssignProperty(x => x.Sku.Capacity, $"{deployment.SkuCapacity}");
cdkDeployments.Add(cdkDeployment);
// Subsequent deployments need an explicit dependency on the previous one
// to ensure they are not created in parallel. This is equivalent to @batchSize(1)
// which can't be defined with the CDK
if (dependency != null)
{
cdkDeployment.AddDependency(dependency);
}
dependency = cdkDeployment;
}
var resourceBuilder = builder.CreateResourceBuilder(resource);
Expand Down
28 changes: 25 additions & 3 deletions tests/Aspire.Hosting.Tests/Azure/AzureBicepResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2249,14 +2249,17 @@ public async Task AddAzureOpenAI()
var openai = builder.AddAzureOpenAI("openai", (_, _, _, deployments) =>
{
aiDeployments = deployments;
}).AddDeployment(new("mymodel", "gpt-35-turbo", "0613", "Basic", 4));
})
.AddDeployment(new("mymodel", "gpt-35-turbo", "0613", "Basic", 4))
.AddDeployment(new("embedding-model", "text-embedding-ada-002", "2", "Basic", 4));

var manifest = await ManifestUtils.GetManifestWithBicep(openai.Resource);

Assert.NotNull(aiDeployments);
Assert.Collection(
aiDeployments,
deployment => Assert.Equal("mymodel", deployment.Properties.Name));
deployment => Assert.Equal("mymodel", deployment.Properties.Name),
deployment => Assert.Equal("embedding-model", deployment.Properties.Name));

var expectedManifest = """
{
Expand Down Expand Up @@ -2323,8 +2326,27 @@ public async Task AddAzureOpenAI()
}
}

output connectionString string = 'Endpoint=${cognitiveServicesAccount_wXAGTFUId.properties.endpoint}'
resource cognitiveServicesAccountDeployment_mdCAJJRlf 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
parent: cognitiveServicesAccount_wXAGTFUId
dependsOn: [
cognitiveServicesAccountDeployment_5K9aRgiZP
]
name: 'embedding-model'
sku: {
name: 'Basic'
capacity: 4
}
properties: {
model: {
format: 'OpenAI'
name: 'text-embedding-ada-002'
version: '2'
}
}
}

output connectionString string = 'Endpoint=${cognitiveServicesAccount_wXAGTFUId.properties.endpoint}'

""";
output.WriteLine(manifest.BicepText);
Assert.Equal(expectedBicep, manifest.BicepText);
Expand Down

0 comments on commit fb8ba84

Please sign in to comment.