Skip to content

Commit

Permalink
Added some throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
RGBKnights committed Jan 8, 2025
1 parent 245c76d commit e3d2d32
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,33 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenAI.Chat;
using ThrottlingTroll;

var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureFunctionsWebApplication((builderContext, workerAppBuilder) => {
workerAppBuilder.UseThrottlingTroll(options => {
options.Config = new ThrottlingTrollConfig
{
Rules =
[
new ThrottlingTrollRule
{
UriPattern = "/api/Iterator_Start",
LimitMethod = new FixedWindowRateLimitMethod
{
PermitLimit = 10,
IntervalInSeconds = 3600,
}
}
]
};
options.IdentityIdExtractor = request =>
{
var httpRequest = ((IIncomingHttpRequestProxy)request).Request;
return httpRequest.HttpContext.Connection.RemoteIpAddress?.ToString();
};
});
})
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
Expand Down
1 change: 1 addition & 0 deletions WhiteCrow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />
<PackageReference Include="OpenAI" Version="2.1.0" />
<PackageReference Include="ThrottlingTroll.AzureFunctionsAspNet" Version="7.3.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down

0 comments on commit e3d2d32

Please sign in to comment.