-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Updated plugin to .net 8 - Added ability to specify fully customizable domain proxies - Added environment variable parsing for ELEVENLABS_API_KEY - Added SoundEffects API endpoints - Added Dubbing API endpoints - Updated default models - Fixed adding and editing Voices --------- Co-authored-by: Austin Hale <[email protected]>
- Loading branch information
1 parent
c7a2a95
commit 1f08fd3
Showing
56 changed files
with
2,133 additions
and
436 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -339,3 +339,4 @@ ASALocalRun/ | |
# BeatPulse healthcheck temp database | ||
healthchecksdb | ||
.vscode | ||
*.dubbed.* |
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
4 changes: 2 additions & 2 deletions
4
ElevenLabs-DotNet-Proxy/Proxy/AbstractAuthenticationFilter.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
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace ElevenLabs.Proxy | ||
{ | ||
/// <summary> | ||
/// Used in ASP.NET Core WebApps to start your own ElevenLabs web api proxy. | ||
/// </summary> | ||
public class ElevenLabsProxy | ||
{ | ||
private ElevenLabsClient elevenLabsClient; | ||
private IAuthenticationFilter authenticationFilter; | ||
|
||
/// <summary> | ||
/// Configures the <see cref="ElevenLabsClient"/> and <see cref="IAuthenticationFilter"/> services. | ||
/// </summary> | ||
/// <param name="services"></param> | ||
public void ConfigureServices(IServiceCollection services) | ||
=> SetupServices(services.BuildServiceProvider()); | ||
|
||
/// <summary> | ||
/// Configures the <see cref="IApplicationBuilder"/> to handle requests and forward them to OpenAI API. | ||
/// </summary> | ||
/// <param name="app"><see cref="IApplicationBuilder"/>.</param> | ||
/// <param name="env"><see cref="IWebHostEnvironment"/>.</param> | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
SetupServices(app.ApplicationServices); | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseRouting(); | ||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapGet("/health", HealthEndpoint); | ||
endpoints.MapElevenLabsEndpoints(elevenLabsClient, authenticationFilter); | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="IHost"/> that acts as a proxy web api for ElevenLabs. | ||
/// </summary> | ||
/// <typeparam name="T"><see cref="IAuthenticationFilter"/> type to use to validate your custom issued tokens.</typeparam> | ||
/// <param name="args">Startup args.</param> | ||
/// <param name="elevenLabsClient"><see cref="ElevenLabsClient"/> with configured <see cref="ElevenLabsAuthentication"/> and <see cref="ElevenLabsClientSettings"/>.</param> | ||
public static IHost CreateDefaultHost<T>(string[] args, ElevenLabsClient elevenLabsClient) where T : class, IAuthenticationFilter | ||
=> Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<ElevenLabsProxy>(); | ||
webBuilder.ConfigureKestrel(ConfigureKestrel); | ||
}) | ||
.ConfigureServices(services => | ||
{ | ||
services.AddSingleton(elevenLabsClient); | ||
services.AddSingleton<IAuthenticationFilter, T>(); | ||
}).Build(); | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="WebApplication"/> that acts as a proxy web api for OpenAI. | ||
/// </summary> | ||
/// <typeparam name="T"><see cref="IAuthenticationFilter"/> type to use to validate your custom issued tokens.</typeparam> | ||
/// <param name="args">Startup args.</param> | ||
/// <param name="elevenLabsClient"><see cref="ElevenLabsClient"/> with configured <see cref="ElevenLabsAuthentication"/> and <see cref="ElevenLabsClientSettings"/>.</param> | ||
public static WebApplication CreateWebApplication<T>(string[] args, ElevenLabsClient elevenLabsClient) where T : class, IAuthenticationFilter | ||
{ | ||
var builder = WebApplication.CreateBuilder(args); | ||
builder.WebHost.ConfigureKestrel(ConfigureKestrel); | ||
builder.Services.AddSingleton(elevenLabsClient); | ||
builder.Services.AddSingleton<IAuthenticationFilter, T>(); | ||
var app = builder.Build(); | ||
var startup = new ElevenLabsProxy(); | ||
startup.Configure(app, app.Environment); | ||
return app; | ||
} | ||
|
||
private static void ConfigureKestrel(KestrelServerOptions options) | ||
{ | ||
options.AllowSynchronousIO = false; | ||
options.Limits.MinRequestBodyDataRate = null; | ||
options.Limits.MinResponseDataRate = null; | ||
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10); | ||
options.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(2); | ||
} | ||
|
||
private void SetupServices(IServiceProvider serviceProvider) | ||
{ | ||
elevenLabsClient = serviceProvider.GetRequiredService<ElevenLabsClient>(); | ||
authenticationFilter = serviceProvider.GetRequiredService<IAuthenticationFilter>(); | ||
} | ||
|
||
private static async Task HealthEndpoint(HttpContext context) | ||
{ | ||
// Respond with a 200 OK status code and a plain text message | ||
context.Response.StatusCode = StatusCodes.Status200OK; | ||
const string contentType = "text/plain"; | ||
context.Response.ContentType = contentType; | ||
const string content = "OK"; | ||
await context.Response.WriteAsync(content); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.