Skip to content

Commit

Permalink
sync fork to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
sikutisa committed Sep 20, 2024
2 parents 24abc54 + 5cdf5f5 commit 75d851a
Show file tree
Hide file tree
Showing 30 changed files with 1,501 additions and 607 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace AzureOpenAIProxy.ApiApp.Configurations;

/// <summary>
/// This represents the settings entity for storage account.
/// </summary>
public class StorageAccountSettings
{
/// <summary>
/// Gets the name of the configuration settings.
/// </summary>
public const string Name = "StorageAccount";

/// <summary>
/// Gets or sets the <see cref="TableStorageSettings"/> instance.
/// </summary>
public TableStorageSettings TableStorage { get; set; } = new();
}
17 changes: 17 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Configurations/TableStorageSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace AzureOpenAIProxy.ApiApp.Configurations;

/// <summary>
/// This represents the settings entity for Azure Table Stroage.
/// </summary>
public class TableStorageSettings
{
/// <summary>
/// Gets the name of the configuration settings.
/// </summary>
public const string Name = "TableStorage";

/// <summary>
/// Gets or sets the table name.
/// </summary>
public string? TableName { get; set; }
}
8 changes: 8 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Endpoints/AdminEndpointUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ public static class AdminEndpointUrls
/// - POST method for new event creation
/// </remarks>
public const string AdminEvents = "/admin/events";

/// <summary>
/// Declares the admin resource details endpoint.
/// </summary>
/// <remarks>
/// - POST method for new resource creation
/// </remarks>
public const string AdminResources = "/admin/resources";
}
54 changes: 54 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Endpoints/AdminResourceEndpoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using AzureOpenAIProxy.ApiApp.Models;
using AzureOpenAIProxy.ApiApp.Services;

using Microsoft.AspNetCore.Mvc;

namespace AzureOpenAIProxy.ApiApp.Endpoints;

/// <summary>
/// This represents the endpoint entity for resource details by admin
/// </summary>
public static class AdminResourceEndpoints
{
/// <summary>
/// Adds the admin resource endpoint
/// </summary>
/// <param name="app"><see cref="WebApplication"/> instance.</param>
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
public static RouteHandlerBuilder AddNewAdminResource(this WebApplication app)
{
var builder = app.MapPost(AdminEndpointUrls.AdminResources, async (
[FromBody] AdminResourceDetails payload,
IAdminEventService service,
ILoggerFactory loggerFactory) =>
{
var logger = loggerFactory.CreateLogger(nameof(AdminResourceEndpoints));
logger.LogInformation("Received a new resource request");
if (payload is null)
{
logger.LogError("No payload found");
return Results.BadRequest("Payload is null");
}
return await Task.FromResult(Results.Ok());
})
.Accepts<AdminResourceDetails>(contentType: "application/json")
.Produces<AdminResourceDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
.Produces(statusCode: StatusCodes.Status400BadRequest)
.Produces(statusCode: StatusCodes.Status401Unauthorized)
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
.WithTags("admin")
.WithName("CreateAdminResource")
.WithOpenApi(operation =>
{
operation.Summary = "Create admin resource";
operation.Description = "Create admin resource";
return operation;
});

return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ public static class PlaygroundEndpointUrls
/// - GET method for listing all events
/// </remarks>
public const string Events = "/events";

/// <summary>
/// Declares the deployment models list endpoint.
/// </summary>
/// <remarks>
/// - GET method for listing all deployment models
/// </remarks>
public const string DeploymentModels = "/events/{eventId}/deployment-models";
}
34 changes: 34 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Endpoints/PlaygroundEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.AspNetCore.Mvc;

namespace AzureOpenAIProxy.ApiApp.Endpoints;

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

return builder;
}


/// <summary>
/// Adds the get deployment models
/// </summary>
/// <param name="app"><see cref="WebApplication"/> instance.</param>
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
public static RouteHandlerBuilder AddListDeploymentModels(this WebApplication app)
{
// Todo: Issue #170 https://github.com/aliencube/azure-openai-sdk-proxy/issues/170
var builder = app.MapGet(PlaygroundEndpointUrls.DeploymentModels, (
[FromRoute] string eventId
) =>
{
return Results.Ok();
})
.Produces<List<DeploymentModelDetails>>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
.Produces(statusCode: StatusCodes.Status401Unauthorized)
.Produces(statusCode: StatusCodes.Status404NotFound)
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
.WithTags("events")
.WithName("GetDeploymentModels")
.WithOpenApi(operation =>
{
operation.Summary = "Gets all deployment models";
operation.Description = "This endpoint gets all deployment models avaliable";
return operation;
});

return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,31 @@ public static IServiceCollection AddTableStorageService(this IServiceCollection
return client;
});

return services;
}

/// <summary>
/// Gets the storage account configuration settings by reading appsettings.json.
/// </summary>
/// <param name="services"><see cref="IServiceCollection"/> instance.</param>
/// <returns>Returns <see cref="StorageAccountSettings"/> instance.</returns>
public static IServiceCollection AddStorageAccountSettings(this IServiceCollection services)
{
services.AddSingleton<StorageAccountSettings>(sp => {
var configuration = sp.GetService<IConfiguration>()
?? throw new InvalidOperationException($"{nameof(IConfiguration)} service is not registered.");
var settings = configuration.GetSection(AzureSettings.Name).GetSection(StorageAccountSettings.Name).Get<StorageAccountSettings>()
?? throw new InvalidOperationException($"{nameof(StorageAccountSettings)} could not be retrieved from the configuration.");
if (string.IsNullOrWhiteSpace(settings.TableStorage.TableName) == true)
{
throw new InvalidOperationException($"{StorageAccountSettings.Name}.{TableStorageSettings.Name} is not defined.");
}
return settings;
});

return services;
}
}
2 changes: 1 addition & 1 deletion src/AzureOpenAIProxy.ApiApp/Filters/OpenApiTagFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
[
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" },
new OpenApiTag { Name = "admin", Description = "Admin operations for managing events and resources" },
new OpenApiTag { Name = "events", Description = "User events" }
];
}
Expand Down
14 changes: 14 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Models/DeploymentModelDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Text.Json.Serialization;

/// <summary>
/// This represent the event detail data for response by admin event endpoint.
/// </summary>
public class DeploymentModelDetails
{
/// <summary>
/// Gets or sets the deployment model name.
/// </summary>
[JsonRequired]
public string Name { get; set; } = string.Empty;

}
6 changes: 6 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 Storage Account settings
builder.Services.AddStorageAccountSettings();

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

Expand Down Expand Up @@ -54,11 +57,14 @@

// Playground endpoints
app.AddListEvents();
app.AddListDeploymentModels();

// Admin endpoints
app.AddNewAdminEvent();
app.AddListAdminEvents();
app.AddGetAdminEvent();
app.AddUpdateAdminEvent();

app.AddNewAdminResource();

await app.RunAsync();
12 changes: 12 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using Azure.Data.Tables;

<<<<<<< HEAD

Check failure on line 3 in src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs

View workflow job for this annotation

GitHub Actions / build-test

Merge conflict marker encountered

Check failure on line 3 in src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs

View workflow job for this annotation

GitHub Actions / build-test

Merge conflict marker encountered
=======

Check failure on line 4 in src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs

View workflow job for this annotation

GitHub Actions / build-test

Merge conflict marker encountered

Check failure on line 4 in src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs

View workflow job for this annotation

GitHub Actions / build-test

Merge conflict marker encountered
using AzureOpenAIProxy.ApiApp.Configurations;
using AzureOpenAIProxy.ApiApp.Extensions;
>>>>>>> main

Check failure on line 7 in src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs

View workflow job for this annotation

GitHub Actions / build-test

Merge conflict marker encountered

Check failure on line 7 in src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs

View workflow job for this annotation

GitHub Actions / build-test

Merge conflict marker encountered
using AzureOpenAIProxy.ApiApp.Models;

namespace AzureOpenAIProxy.ApiApp.Repositories;
Expand Down Expand Up @@ -41,9 +46,16 @@ public interface IAdminEventRepository
/// <summary>
/// This represents the repository entity for the admin event.
/// </summary>
<<<<<<< HEAD

Check failure on line 49 in src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs

View workflow job for this annotation

GitHub Actions / build-test

Merge conflict marker encountered

Check failure on line 49 in src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs

View workflow job for this annotation

GitHub Actions / build-test

Merge conflict marker encountered
public class AdminEventRepository(TableServiceClient tableServiceClient) : IAdminEventRepository
{
private readonly TableServiceClient _tableServiceClient = tableServiceClient ?? throw new ArgumentNullException(nameof(tableServiceClient));
=======

Check failure on line 53 in src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs

View workflow job for this annotation

GitHub Actions / build-test

Merge conflict marker encountered
public class AdminEventRepository(TableServiceClient tableServiceClient, StorageAccountSettings storageAccountSettings) : IAdminEventRepository
{
private readonly TableServiceClient _tableServiceClient = tableServiceClient ?? throw new ArgumentNullException(nameof(tableServiceClient));
private readonly StorageAccountSettings _storageAccountSettings = storageAccountSettings ?? throw new ArgumentNullException(nameof(storageAccountSettings));
>>>>>>> main

Check failure on line 58 in src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs

View workflow job for this annotation

GitHub Actions / build-test

Merge conflict marker encountered

/// <inheritdoc />
public async Task<AdminEventDetails> CreateEvent(AdminEventDetails eventDetails)
Expand Down
5 changes: 5 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"OpenAI": "azure-openai-instances",
"Storage": "storage-connection-string"
}
},
"StorageAccount": {
"TableStorage": {
"TableName": "events"
}
}
},

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@page "/"
@using AzureOpenAIProxy.PlaygroundApp.Components.UI

<PageTitle>Home</PageTitle>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<FluentGrid Spacing="3" AdaptiveRendering="true" Justify="JustifyContent.FlexStart">
<FluentGridItem Class="config-grid" xs="12" sm="12" md="4" lg="4" xl="4" xxl="4">
<ConfigTabComponent @rendermode="InteractiveServer"/>
<ConfigWindowComponent Id="config-window" @rendermode="InteractiveServer" />
</FluentGridItem>

<FluentGridItem Class="chat-grid" xs="12" sm="12" md="8" lg="8" xl="8" xxl="8" Style="height: 900px;">
Expand Down
29 changes: 0 additions & 29 deletions src/AzureOpenAIProxy.PlaygroundApp/Components/Pages/Tests.razor

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<FluentStack Id="@Id" Style="width: 100%;" Orientation="Orientation.Vertical" VerticalAlignment="VerticalAlignment.Top">
<FluentTextField Id="api-key-field" Label="API key" Required="true"
TextFieldType="TextFieldType.Password"
Placeholder="Enter API key"
@bind-Value="apiKeyValue"
@oninput="SetApiKey" />
</FluentStack>

@code {
private string? apiKeyValue { get; set; }

[Parameter]
public string? Id { get; set; }

[Parameter]
public EventCallback<string> OnKeyInput { get; set; }

private async Task SetApiKey(ChangeEventArgs e)
{
apiKeyValue = e.Value!.ToString();
if (string.IsNullOrWhiteSpace(apiKeyValue) == true)
{
return;
}

await OnKeyInput.InvokeAsync(apiKeyValue);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<FluentTabs Id="config-tab" ActiveTabId="system-message" OnTabChange="ChangeTab">
<FluentTab Label="System message" Id="system-message-tab">
This is "System message" tab.
</FluentTab>
<FluentTab Label="Parameters" Id="parameters-tab">
This is "Parameters" tab.
</FluentTab>
</FluentTabs>

<p id="active-tab">[TEST] Active tab changed to: @SelectedTab?.Id</p>
<FluentStack Id="@Id" Style="width: 100%;" Orientation="Orientation.Vertical" VerticalAlignment="VerticalAlignment.Top">
<FluentTabs Id="config-tabs" Style="width: 100%;" ActiveTabId="system-message-tab" OnTabChange="ChangeTab">
<FluentTab Id="system-message-tab" Label="System message">
This is "System message" tab.
</FluentTab>
<FluentTab Id="parameters-tab" Label="Parameters">
This is "Parameters" tab.
</FluentTab>
</FluentTabs>
</FluentStack>

@code {
FluentTab? SelectedTab;
private FluentTab? selectedTab { get; set; }

[Parameter]
public string? Id { get; set; }

private async Task ChangeTab(FluentTab tab)
{
SelectedTab = tab;
this.selectedTab = tab;
await Task.CompletedTask;
}
}
Loading

0 comments on commit 75d851a

Please sign in to comment.