-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
287 additions
and
117 deletions.
There are no files selected for viewing
25 changes: 17 additions & 8 deletions
25
src/AzureOpenAIProxy.ApiApp/Endpoints/AdminEndpointUrls.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
namespace AzureOpenAIProxy.ApiApp.Endpoints; | ||
|
||
public static class AdminEndpointUrls | ||
{ | ||
/// <summary> | ||
/// Declares the admin event details endpoint. | ||
/// </summary> | ||
public const string AdminEventDetails = "/admin/events/{eventId}"; | ||
namespace AzureOpenAIProxy.ApiApp.Endpoints; | ||
|
||
public static class AdminEndpointUrls | ||
{ | ||
/// <summary> | ||
/// Declares the admin event details endpoint. | ||
/// </summary> | ||
public const string AdminEventDetails = "/admin/events/{eventId}"; | ||
|
||
/// <summary> | ||
/// Declares the admin event list endpoint. | ||
/// </summary> | ||
/// <remarks> | ||
/// - Get method for listing all events | ||
/// - Post method for new event creation | ||
/// </remarks> | ||
public const string AdminEvents = "/admin/events"; | ||
} |
117 changes: 74 additions & 43 deletions
117
src/AzureOpenAIProxy.ApiApp/Endpoints/AdminEventEndpoints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,74 @@ | ||
using AzureOpenAIProxy.ApiApp.Models; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace AzureOpenAIProxy.ApiApp.Endpoints; | ||
|
||
/// <summary> | ||
/// This represents the endpoint entity for get event details by admin | ||
/// </summary> | ||
public static class AdminEventEndpoints | ||
{ | ||
/// <summary> | ||
/// Adds the get event details by admin endpoint | ||
/// </summary> | ||
/// <param name="app"><see cref="WebApplication"/> instance.</param> | ||
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns> | ||
public static RouteHandlerBuilder AddAdminEvents(this WebApplication app) | ||
{ | ||
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19 | ||
// Need authorization by admin | ||
var builder = app.MapGet(AdminEndpointUrls.AdminEventDetails, ( | ||
[FromRoute] string eventId) => | ||
{ | ||
// Todo: Issue #208 https://github.com/aliencube/azure-openai-sdk-proxy/issues/208 | ||
return Results.Ok(); | ||
// Todo: Issue #208 | ||
}) | ||
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json") | ||
.Produces(statusCode: StatusCodes.Status401Unauthorized) | ||
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain") | ||
.WithTags("admin") | ||
.WithName("GetAdminEventDetails") | ||
.WithOpenApi(operation => | ||
{ | ||
operation.Summary = "Gets event details from the given event ID"; | ||
operation.Description = "This endpoint gets the event details from the given event ID."; | ||
return operation; | ||
}); | ||
|
||
return builder; | ||
} | ||
} | ||
using AzureOpenAIProxy.ApiApp.Models; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace AzureOpenAIProxy.ApiApp.Endpoints; | ||
|
||
/// <summary> | ||
/// This represents the endpoint entity for get event details by admin | ||
/// </summary> | ||
public static class AdminEventEndpoints | ||
{ | ||
/// <summary> | ||
/// Adds the get event details by admin endpoint | ||
/// </summary> | ||
/// <param name="app"><see cref="WebApplication"/> instance.</param> | ||
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns> | ||
public static RouteHandlerBuilder AddAdminEvents(this WebApplication app) | ||
{ | ||
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19 | ||
// Need authorization by admin | ||
var builder = app.MapGet(AdminEndpointUrls.AdminEventDetails, ( | ||
[FromRoute] string eventId) => | ||
{ | ||
// Todo: Issue #208 https://github.com/aliencube/azure-openai-sdk-proxy/issues/208 | ||
return Results.Ok(); | ||
// Todo: Issue #208 | ||
}) | ||
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json") | ||
.Produces(statusCode: StatusCodes.Status401Unauthorized) | ||
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain") | ||
.WithTags("admin") | ||
.WithName("GetAdminEventDetails") | ||
.WithOpenApi(operation => | ||
{ | ||
operation.Summary = "Gets event details from the given event ID"; | ||
operation.Description = "This endpoint gets the event details from the given event ID."; | ||
return operation; | ||
}); | ||
|
||
return builder; | ||
} | ||
|
||
/// <summary> | ||
/// Adds the get event lists by admin endpoint | ||
/// </summary> | ||
/// <param name="app"><see cref="WebApplication"/> instance.</param> | ||
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns> | ||
public static RouteHandlerBuilder AddAdminEventList(this WebApplication app) | ||
{ | ||
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19 | ||
// Need authorization by admin | ||
var builder = app.MapGet(AdminEndpointUrls.AdminEvents, () => | ||
{ | ||
// Todo: Issue #218 https://github.com/aliencube/azure-openai-sdk-proxy/issues/218 | ||
return Results.Ok(); | ||
// Todo: Issue #218 | ||
}) | ||
.Produces<List<AdminEventDetails>>(statusCode: StatusCodes.Status200OK, contentType: "application/json") | ||
.Produces(statusCode: StatusCodes.Status401Unauthorized) | ||
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain") | ||
.WithTags("admin") | ||
.WithName("GetAdminEvents") | ||
.WithOpenApi(operation => | ||
{ | ||
operation.Summary = "Gets all events"; | ||
operation.Description = "This endpoint gets all events"; | ||
return operation; | ||
}); | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
using Microsoft.OpenApi.Models; | ||
|
||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace AzureOpenAIProxy.ApiApp.Filters; | ||
|
||
/// <summary> | ||
/// This represents the document filter entity for global tags. | ||
/// </summary> | ||
public class OpenApiTagFilter : IDocumentFilter | ||
{ | ||
/// <inheritdoc /> | ||
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) | ||
{ | ||
swaggerDoc.Tags = | ||
[ | ||
new OpenApiTag { Name = "weather", Description = "Weather forecast operations" }, | ||
new OpenApiTag { Name = "openai", Description = "Azure OpenAI operations" }, | ||
]; | ||
} | ||
} | ||
using Microsoft.OpenApi.Models; | ||
|
||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace AzureOpenAIProxy.ApiApp.Filters; | ||
|
||
/// <summary> | ||
/// This represents the document filter entity for global tags. | ||
/// </summary> | ||
public class OpenApiTagFilter : IDocumentFilter | ||
{ | ||
/// <inheritdoc /> | ||
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) | ||
{ | ||
swaggerDoc.Tags = | ||
[ | ||
new OpenApiTag { Name = "weather", Description = "Weather forecast operations" }, | ||
new OpenApiTag { Name = "openai", Description = "Azure OpenAI operations" }, | ||
new OpenApiTag { Name = "admin", Description = "Admin for organizing events" } | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,46 @@ | ||
using AzureOpenAIProxy.ApiApp.Endpoints; | ||
using AzureOpenAIProxy.ApiApp.Extensions; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.AddServiceDefaults(); | ||
|
||
// Add KeyVault service | ||
builder.Services.AddKeyVaultService(); | ||
|
||
// Add Azure OpenAI service. | ||
builder.Services.AddOpenAIService(); | ||
|
||
// Add OpenAPI service | ||
builder.Services.AddOpenApiService(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapDefaultEndpoints(); | ||
|
||
// https://stackoverflow.com/questions/76962735/how-do-i-set-a-prefix-in-my-asp-net-core-7-web-api-for-all-endpoints | ||
var basePath = "/api"; | ||
app.UsePathBase(basePath); | ||
app.UseRouting(); | ||
|
||
// Configure the HTTP request pipeline. | ||
// Use Swagger UI | ||
app.UseSwaggerUI(basePath); | ||
|
||
// Enable buffering | ||
app.Use(async (context, next) => | ||
{ | ||
context.Request.EnableBuffering(); | ||
await next.Invoke(); | ||
}); | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.AddWeatherForecast(); | ||
app.AddChatCompletions(); | ||
|
||
// Admin Endpoints | ||
app.AddAdminEvents(); | ||
|
||
await app.RunAsync(); | ||
using AzureOpenAIProxy.ApiApp.Endpoints; | ||
using AzureOpenAIProxy.ApiApp.Extensions; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.AddServiceDefaults(); | ||
|
||
// Add KeyVault service | ||
builder.Services.AddKeyVaultService(); | ||
|
||
// Add Azure OpenAI service. | ||
builder.Services.AddOpenAIService(); | ||
|
||
// Add OpenAPI service | ||
builder.Services.AddOpenApiService(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapDefaultEndpoints(); | ||
|
||
// https://stackoverflow.com/questions/76962735/how-do-i-set-a-prefix-in-my-asp-net-core-7-web-api-for-all-endpoints | ||
var basePath = "/api"; | ||
app.UsePathBase(basePath); | ||
app.UseRouting(); | ||
|
||
// Configure the HTTP request pipeline. | ||
// Use Swagger UI | ||
app.UseSwaggerUI(basePath); | ||
|
||
// Enable buffering | ||
app.Use(async (context, next) => | ||
{ | ||
context.Request.EnableBuffering(); | ||
await next.Invoke(); | ||
}); | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.AddWeatherForecast(); | ||
app.AddChatCompletions(); | ||
|
||
// Admin Endpoints | ||
app.AddAdminEvents(); | ||
app.AddAdminEventList(); | ||
|
||
await app.RunAsync(); |
Oops, something went wrong.