-
Notifications
You must be signed in to change notification settings - Fork 577
/
Copy pathAzureOpenAIResource.cs
58 lines (49 loc) · 2.22 KB
/
AzureOpenAIResource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.Hosting.Azure;
using Azure.Provisioning.CognitiveServices;
using Azure.Provisioning.Primitives;
namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// Represents an Azure OpenAI resource.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="configureInfrastructure">Configures the underlying Azure resource using the CDK.</param>
public class AzureOpenAIResource(string name, Action<AzureResourceInfrastructure> configureInfrastructure) :
AzureProvisioningResource(name, configureInfrastructure),
IResourceWithConnectionString,
IResourceWithEnvironment
{
private readonly List<AzureOpenAIDeployment> _deployments = [];
/// <summary>
/// Gets the "connectionString" output reference from the Azure OpenAI resource.
/// </summary>
public BicepOutputReference ConnectionString => new("connectionString", this);
private BicepOutputReference NameOutputReference => new("name", this);
/// <summary>
/// Gets the connection string template for the manifest for the resource.
/// </summary>
public ReferenceExpression ConnectionStringExpression =>
ReferenceExpression.Create($"{ConnectionString}");
/// <summary>
/// Gets the list of deployments of the Azure OpenAI resource.
/// </summary>
public IReadOnlyList<AzureOpenAIDeployment> Deployments => _deployments;
/// <summary>
/// Adds an <see cref="AzureOpenAIDeployment"/> instance to the list of deployments.
/// </summary>
/// <param name="deployment">The <see cref="AzureOpenAIDeployment"/> instance to add.</param>
public void AddDeployment(AzureOpenAIDeployment deployment)
{
ArgumentNullException.ThrowIfNull(deployment);
_deployments.Add(deployment);
}
/// <inheritdoc/>
public override ProvisionableResource AddAsExistingResource(AzureResourceInfrastructure infra)
{
var account = CognitiveServicesAccount.FromExisting(this.GetBicepIdentifier());
account.Name = NameOutputReference.AsProvisioningParameter(infra);
infra.Add(account);
return account;
}
}