Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/AzureOpenAIProxy.ApiApp/AzureOpenAIProxy.ApiApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="$(AzureOpenAIVersion)" />
<PackageReference Include="Azure.Data.Tables" Version="12.9.0" />
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.6.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="$(AspNetCoreVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class KeyVaultSettings
public string? VaultUri { get; set; }

/// <summary>
/// Gets or sets the secret name.
/// Gets or sets the secret names.
/// </summary>
public string? SecretName { get; set; }
public IDictionary<string, string> SecretNames { get; set; } = new Dictionary<string, string>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static IOpenAISettingsBuilder WithKeyVault(this IOpenAISettingsBuilder bu
var client = sp.GetService<SecretClient>()
?? throw new InvalidOperationException($"{nameof(SecretClient)} service is not registered.");

var value = client.GetSecret(settings.SecretName!).Value.Value;
var value = client.GetSecret(settings.SecretNames["OpenAI"]!).Value.Value;

var instances = JsonSerializer.Deserialize<List<OpenAIInstanceSettings>>(value);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Azure.Identity;
using Azure;
using Azure.Data.Tables;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;

using AzureOpenAIProxy.ApiApp.Builders;
Expand Down Expand Up @@ -35,9 +37,9 @@ public static IServiceCollection AddKeyVaultService(this IServiceCollection serv
throw new InvalidOperationException($"{nameof(KeyVaultSettings.VaultUri)} is not defined.");
}

if (string.IsNullOrWhiteSpace(settings.SecretName) == true)
if (string.IsNullOrWhiteSpace(settings.SecretNames["OpenAI"]) == true)
{
throw new InvalidOperationException($"{nameof(KeyVaultSettings.SecretName)} is not defined.");
throw new InvalidOperationException($"{nameof(KeyVaultSettings.SecretNames)}.OpenAI is not defined.");
}

var client = new SecretClient(new Uri(settings.VaultUri), new DefaultAzureCredential());
Expand Down Expand Up @@ -134,4 +136,31 @@ public static IServiceCollection AddOpenApiService(this IServiceCollection servi

return services;
}

/// <summary>
/// Adds the TableServiceClient to the services collection.
/// </summary>
/// <param name="services"><see cref="IServiceCollection"/> instance.</param>
/// <returns>Returns <see cref="IServiceCollection"/> instance.</returns>
public static IServiceCollection AddTableStorageService(this IServiceCollection services)
{
services.AddSingleton<TableServiceClient>(sp => {
var configuration = sp.GetService<IConfiguration>()
?? throw new InvalidOperationException($"{nameof(IConfiguration)} service is not registerd.");

var settings = configuration.GetSection(AzureSettings.Name).GetSection(KeyVaultSettings.Name).Get<KeyVaultSettings>()
?? throw new InvalidOperationException($"{nameof(KeyVaultSettings)} could not be retrieved from the configuration.");

var clientSecret = sp.GetService<SecretClient>()
?? throw new InvalidOperationException($"{nameof(SecretClient)} service is not registered.");

var storageKeyVault = clientSecret.GetSecret(settings.SecretNames["Storage"]!);

var client = new TableServiceClient(storageKeyVault.Value.Value);

return client;
});

return services;
}
}
3 changes: 3 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
// Add OpenAPI service
builder.Services.AddOpenApiService();

// Add TableStorageClient
builder.Services.AddTableStorageService();

// Add admin services
builder.Services.AddAdminEventService();

Expand Down
5 changes: 4 additions & 1 deletion src/AzureOpenAIProxy.ApiApp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
},
"KeyVault": {
"VaultUri": "https://{{key-vault-name}}.vault.azure.net/",
"SecretName": "azure-openai-instances"
"SecretNames": {
"OpenAI": "azure-openai-instances",
"Storage": "storage-connection-string"
}
}
},

Expand Down