2024-07-10 02:17:36 +00:00
|
|
|
using BotSharp.Abstraction.Plugins;
|
|
|
|
|
using BotSharp.Abstraction.Settings;
|
|
|
|
|
using BotSharp.Plugin.OpenAI.Providers.Embedding;
|
|
|
|
|
using BotSharp.Plugin.OpenAI.Providers.Image;
|
|
|
|
|
using BotSharp.Plugin.OpenAI.Providers.Text;
|
|
|
|
|
using BotSharp.Plugin.OpenAI.Providers.Chat;
|
2024-08-08 19:54:32 +00:00
|
|
|
using BotSharp.Plugin.OpenAI.Providers.Audio;
|
2024-08-28 16:08:12 +00:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2025-02-03 04:02:36 +00:00
|
|
|
using Refit;
|
|
|
|
|
using BotSharp.Plugin.OpenAI.Providers.Realtime;
|
2024-07-10 02:17:36 +00:00
|
|
|
|
|
|
|
|
namespace BotSharp.Plugin.OpenAI;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// OpenAI Service
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class OpenAiPlugin : IBotSharpPlugin
|
|
|
|
|
{
|
|
|
|
|
public string Id => "a743e90f-7cbc-4e47-b8a0-2f8e44f894c7";
|
|
|
|
|
public string Name => "OpenAI";
|
|
|
|
|
public string Description => "OpenAI Service including text generation, text to image and other AI services.";
|
|
|
|
|
public string IconUrl => "https://logosandtypes.com/wp-content/uploads/2022/07/openai.svg";
|
|
|
|
|
|
|
|
|
|
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
services.AddScoped(provider =>
|
|
|
|
|
{
|
|
|
|
|
var settingService = provider.GetRequiredService<ISettingService>();
|
|
|
|
|
return settingService.Bind<OpenAiSettings>("OpenAi");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
services.AddScoped<ITextCompletion, TextCompletionProvider>();
|
|
|
|
|
services.AddScoped<IChatCompletion, ChatCompletionProvider>();
|
|
|
|
|
services.AddScoped<ITextEmbedding, TextEmbeddingProvider>();
|
2024-07-19 03:28:24 +00:00
|
|
|
services.AddScoped<IImageCompletion, ImageCompletionProvider>();
|
2025-03-22 00:28:22 +00:00
|
|
|
services.AddScoped<IAudioTranscription, AudioTranscriptionProvider>();
|
|
|
|
|
services.AddScoped<IAudioSynthesis, AudioSynthesisProvider>();
|
2025-02-03 04:02:36 +00:00
|
|
|
services.AddScoped<IRealTimeCompletion, RealTimeCompletionProvider>();
|
|
|
|
|
|
|
|
|
|
services.AddRefitClient<IOpenAiRealtimeApi>()
|
|
|
|
|
.ConfigureHttpClient(c => c.BaseAddress = new Uri("https://api.openai.com"));
|
2024-07-10 02:17:36 +00:00
|
|
|
}
|
|
|
|
|
}
|