Skip to content

Commit fb075a3

Browse files
committed
sync fork to upstream
2 parents 24abc54 + 5cdf5f5 commit fb075a3

30 files changed

+1501
-607
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace AzureOpenAIProxy.ApiApp.Configurations;
2+
3+
/// <summary>
4+
/// This represents the settings entity for storage account.
5+
/// </summary>
6+
public class StorageAccountSettings
7+
{
8+
/// <summary>
9+
/// Gets the name of the configuration settings.
10+
/// </summary>
11+
public const string Name = "StorageAccount";
12+
13+
/// <summary>
14+
/// Gets or sets the <see cref="TableStorageSettings"/> instance.
15+
/// </summary>
16+
public TableStorageSettings TableStorage { get; set; } = new();
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace AzureOpenAIProxy.ApiApp.Configurations;
2+
3+
/// <summary>
4+
/// This represents the settings entity for Azure Table Stroage.
5+
/// </summary>
6+
public class TableStorageSettings
7+
{
8+
/// <summary>
9+
/// Gets the name of the configuration settings.
10+
/// </summary>
11+
public const string Name = "TableStorage";
12+
13+
/// <summary>
14+
/// Gets or sets the table name.
15+
/// </summary>
16+
public string? TableName { get; set; }
17+
}

src/AzureOpenAIProxy.ApiApp/Endpoints/AdminEndpointUrls.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ public static class AdminEndpointUrls
2222
/// - POST method for new event creation
2323
/// </remarks>
2424
public const string AdminEvents = "/admin/events";
25+
26+
/// <summary>
27+
/// Declares the admin resource details endpoint.
28+
/// </summary>
29+
/// <remarks>
30+
/// - POST method for new resource creation
31+
/// </remarks>
32+
public const string AdminResources = "/admin/resources";
2533
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using AzureOpenAIProxy.ApiApp.Models;
2+
using AzureOpenAIProxy.ApiApp.Services;
3+
4+
using Microsoft.AspNetCore.Mvc;
5+
6+
namespace AzureOpenAIProxy.ApiApp.Endpoints;
7+
8+
/// <summary>
9+
/// This represents the endpoint entity for resource details by admin
10+
/// </summary>
11+
public static class AdminResourceEndpoints
12+
{
13+
/// <summary>
14+
/// Adds the admin resource endpoint
15+
/// </summary>
16+
/// <param name="app"><see cref="WebApplication"/> instance.</param>
17+
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
18+
public static RouteHandlerBuilder AddNewAdminResource(this WebApplication app)
19+
{
20+
var builder = app.MapPost(AdminEndpointUrls.AdminResources, async (
21+
[FromBody] AdminResourceDetails payload,
22+
IAdminEventService service,
23+
ILoggerFactory loggerFactory) =>
24+
{
25+
var logger = loggerFactory.CreateLogger(nameof(AdminResourceEndpoints));
26+
logger.LogInformation("Received a new resource request");
27+
28+
if (payload is null)
29+
{
30+
logger.LogError("No payload found");
31+
32+
return Results.BadRequest("Payload is null");
33+
}
34+
35+
return await Task.FromResult(Results.Ok());
36+
})
37+
.Accepts<AdminResourceDetails>(contentType: "application/json")
38+
.Produces<AdminResourceDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
39+
.Produces(statusCode: StatusCodes.Status400BadRequest)
40+
.Produces(statusCode: StatusCodes.Status401Unauthorized)
41+
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
42+
.WithTags("admin")
43+
.WithName("CreateAdminResource")
44+
.WithOpenApi(operation =>
45+
{
46+
operation.Summary = "Create admin resource";
47+
operation.Description = "Create admin resource";
48+
49+
return operation;
50+
});
51+
52+
return builder;
53+
}
54+
}

src/AzureOpenAIProxy.ApiApp/Endpoints/PlaygroundEndpointUrls.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ public static class PlaygroundEndpointUrls
1212
/// - GET method for listing all events
1313
/// </remarks>
1414
public const string Events = "/events";
15+
16+
/// <summary>
17+
/// Declares the deployment models list endpoint.
18+
/// </summary>
19+
/// <remarks>
20+
/// - GET method for listing all deployment models
21+
/// </remarks>
22+
public const string DeploymentModels = "/events/{eventId}/deployment-models";
1523
}

src/AzureOpenAIProxy.ApiApp/Endpoints/PlaygroundEndpoints.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
13
namespace AzureOpenAIProxy.ApiApp.Endpoints;
24

35
/// <summary>
@@ -32,4 +34,36 @@ public static RouteHandlerBuilder AddListEvents(this WebApplication app)
3234

3335
return builder;
3436
}
37+
38+
39+
/// <summary>
40+
/// Adds the get deployment models
41+
/// </summary>
42+
/// <param name="app"><see cref="WebApplication"/> instance.</param>
43+
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
44+
public static RouteHandlerBuilder AddListDeploymentModels(this WebApplication app)
45+
{
46+
// Todo: Issue #170 https://github.com/aliencube/azure-openai-sdk-proxy/issues/170
47+
var builder = app.MapGet(PlaygroundEndpointUrls.DeploymentModels, (
48+
[FromRoute] string eventId
49+
) =>
50+
{
51+
return Results.Ok();
52+
})
53+
.Produces<List<DeploymentModelDetails>>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
54+
.Produces(statusCode: StatusCodes.Status401Unauthorized)
55+
.Produces(statusCode: StatusCodes.Status404NotFound)
56+
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
57+
.WithTags("events")
58+
.WithName("GetDeploymentModels")
59+
.WithOpenApi(operation =>
60+
{
61+
operation.Summary = "Gets all deployment models";
62+
operation.Description = "This endpoint gets all deployment models avaliable";
63+
64+
return operation;
65+
});
66+
67+
return builder;
68+
}
3569
}

src/AzureOpenAIProxy.ApiApp/Extensions/ServiceCollectionExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,31 @@ public static IServiceCollection AddTableStorageService(this IServiceCollection
165165
return client;
166166
});
167167

168+
return services;
169+
}
170+
171+
/// <summary>
172+
/// Gets the storage account configuration settings by reading appsettings.json.
173+
/// </summary>
174+
/// <param name="services"><see cref="IServiceCollection"/> instance.</param>
175+
/// <returns>Returns <see cref="StorageAccountSettings"/> instance.</returns>
176+
public static IServiceCollection AddStorageAccountSettings(this IServiceCollection services)
177+
{
178+
services.AddSingleton<StorageAccountSettings>(sp => {
179+
var configuration = sp.GetService<IConfiguration>()
180+
?? throw new InvalidOperationException($"{nameof(IConfiguration)} service is not registered.");
181+
182+
var settings = configuration.GetSection(AzureSettings.Name).GetSection(StorageAccountSettings.Name).Get<StorageAccountSettings>()
183+
?? throw new InvalidOperationException($"{nameof(StorageAccountSettings)} could not be retrieved from the configuration.");
184+
185+
if (string.IsNullOrWhiteSpace(settings.TableStorage.TableName) == true)
186+
{
187+
throw new InvalidOperationException($"{StorageAccountSettings.Name}.{TableStorageSettings.Name} is not defined.");
188+
}
189+
190+
return settings;
191+
});
192+
168193
return services;
169194
}
170195
}

src/AzureOpenAIProxy.ApiApp/Filters/OpenApiTagFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
1616
[
1717
new OpenApiTag { Name = "weather", Description = "Weather forecast operations" },
1818
new OpenApiTag { Name = "openai", Description = "Azure OpenAI operations" },
19-
new OpenApiTag { Name = "admin", Description = "Admin for organizing events" },
19+
new OpenApiTag { Name = "admin", Description = "Admin operations for managing events and resources" },
2020
new OpenApiTag { Name = "events", Description = "User events" }
2121
];
2222
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Text.Json.Serialization;
2+
3+
/// <summary>
4+
/// This represent the event detail data for response by admin event endpoint.
5+
/// </summary>
6+
public class DeploymentModelDetails
7+
{
8+
/// <summary>
9+
/// Gets or sets the deployment model name.
10+
/// </summary>
11+
[JsonRequired]
12+
public string Name { get; set; } = string.Empty;
13+
14+
}

src/AzureOpenAIProxy.ApiApp/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// Add OpenAPI service
1717
builder.Services.AddOpenApiService();
1818

19+
// Add Storage Account settings
20+
builder.Services.AddStorageAccountSettings();
21+
1922
// Add TableStorageClient
2023
builder.Services.AddTableStorageService();
2124

@@ -54,11 +57,14 @@
5457

5558
// Playground endpoints
5659
app.AddListEvents();
60+
app.AddListDeploymentModels();
5761

5862
// Admin endpoints
5963
app.AddNewAdminEvent();
6064
app.AddListAdminEvents();
6165
app.AddGetAdminEvent();
6266
app.AddUpdateAdminEvent();
6367

68+
app.AddNewAdminResource();
69+
6470
await app.RunAsync();

0 commit comments

Comments
 (0)