commit
098aa92be2
|
|
@ -1,4 +1,3 @@
|
|||
using BotSharp.Abstraction.Evaluations.Settings;
|
||||
using BotSharp.Abstraction.MLTasks;
|
||||
using BotSharp.Abstraction.Plugins;
|
||||
using BotSharp.Abstraction.Settings;
|
||||
|
|
@ -6,7 +5,6 @@ using BotSharp.Plugin.AzureOpenAI.Providers;
|
|||
using BotSharp.Plugin.AzureOpenAI.Settings;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
|
||||
namespace BotSharp.Platform.AzureAi;
|
||||
|
||||
|
|
@ -16,8 +14,8 @@ namespace BotSharp.Platform.AzureAi;
|
|||
public class AzureOpenAiPlugin : IBotSharpPlugin
|
||||
{
|
||||
public string Id => "65185362-392c-44fd-a023-95a198824436";
|
||||
public string Name => "Azure OpenAI";
|
||||
public string Description => "Azure OpenAI Service including text generation, text to image and other AI services.";
|
||||
public string Name => "OpenAI/ Azure OpenAI";
|
||||
public string Description => "OpenAI/ Azure OpenAI Service including text generation, text to image and other AI services.";
|
||||
public string IconUrl => "https://nanfor.com/cdn/shop/files/cursos-propios-Azure-openAI.jpg?v=1692877741";
|
||||
|
||||
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
||||
|
|
@ -30,5 +28,6 @@ public class AzureOpenAiPlugin : IBotSharpPlugin
|
|||
|
||||
services.AddScoped<ITextCompletion, TextCompletionProvider>();
|
||||
services.AddScoped<IChatCompletion, ChatCompletionProvider>();
|
||||
services.AddScoped<IChatCompletion, OpenAiChatCompletionProvider>();
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.14" />
|
||||
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ namespace BotSharp.Plugin.AzureOpenAI.Providers;
|
|||
|
||||
public class ChatCompletionProvider : IChatCompletion
|
||||
{
|
||||
private readonly AzureOpenAiSettings _settings;
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private string _model;
|
||||
protected readonly AzureOpenAiSettings _settings;
|
||||
protected readonly IServiceProvider _services;
|
||||
protected readonly ILogger _logger;
|
||||
|
||||
public string Provider => "azure-openai";
|
||||
protected string _model;
|
||||
|
||||
public virtual string Provider => "azure-openai";
|
||||
|
||||
public ChatCompletionProvider(AzureOpenAiSettings settings,
|
||||
ILogger<ChatCompletionProvider> logger,
|
||||
|
|
@ -45,7 +45,7 @@ public class ChatCompletionProvider : IChatCompletion
|
|||
await hook.BeforeGenerating(agent, conversations);
|
||||
}
|
||||
|
||||
var client = ProviderHelper.GetClient(_model, _services);
|
||||
var client = ProviderHelper.GetClient(Provider, _model, _services);
|
||||
var (prompt, chatCompletionsOptions) = PrepareOptions(agent, conversations);
|
||||
chatCompletionsOptions.DeploymentName = _model;
|
||||
var response = client.GetChatCompletions(chatCompletionsOptions);
|
||||
|
|
@ -104,7 +104,7 @@ public class ChatCompletionProvider : IChatCompletion
|
|||
await hook.BeforeGenerating(agent, conversations);
|
||||
}
|
||||
|
||||
var client = ProviderHelper.GetClient(_model, _services);
|
||||
var client = ProviderHelper.GetClient(Provider, _model, _services);
|
||||
var (prompt, chatCompletionsOptions) = PrepareOptions(agent, conversations);
|
||||
|
||||
chatCompletionsOptions.DeploymentName = _model;
|
||||
|
|
@ -161,7 +161,7 @@ public class ChatCompletionProvider : IChatCompletion
|
|||
|
||||
public async Task<bool> GetChatCompletionsStreamingAsync(Agent agent, List<RoleDialogModel> conversations, Func<RoleDialogModel, Task> onMessageReceived)
|
||||
{
|
||||
var client = ProviderHelper.GetClient(_model, _services);
|
||||
var client = ProviderHelper.GetClient(Provider, _model, _services);
|
||||
var (prompt, chatCompletionsOptions) = PrepareOptions(agent, conversations);
|
||||
chatCompletionsOptions.DeploymentName = _model;
|
||||
var response = await client.GetChatCompletionsStreamingAsync(chatCompletionsOptions);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
using BotSharp.Plugin.AzureOpenAI.Settings;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
|
||||
namespace BotSharp.Plugin.AzureOpenAI.Providers;
|
||||
|
||||
public class OpenAiChatCompletionProvider : ChatCompletionProvider
|
||||
{
|
||||
public override string Provider => "openai";
|
||||
|
||||
public OpenAiChatCompletionProvider(AzureOpenAiSettings settings,
|
||||
ILogger<OpenAiChatCompletionProvider> logger,
|
||||
IServiceProvider services) : base(settings, logger, services)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -10,11 +10,13 @@ namespace BotSharp.Plugin.AzureOpenAI.Providers;
|
|||
|
||||
public class ProviderHelper
|
||||
{
|
||||
public static OpenAIClient GetClient(string model, IServiceProvider services)
|
||||
public static OpenAIClient GetClient(string provider, string model, IServiceProvider services)
|
||||
{
|
||||
var settingsService = services.GetRequiredService<ILlmProviderService>();
|
||||
var settings = settingsService.GetSetting("azure-openai", model);
|
||||
var client = new OpenAIClient(new Uri(settings.Endpoint), new AzureKeyCredential(settings.ApiKey));
|
||||
var settings = settingsService.GetSetting(provider, model);
|
||||
var client = provider == "openai" ?
|
||||
new OpenAIClient($"{settings.ApiKey}") :
|
||||
new OpenAIClient(new Uri(settings.Endpoint), new AzureKeyCredential(settings.ApiKey));
|
||||
return client;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class TextCompletionProvider : ITextCompletion
|
|||
message
|
||||
})).ToArray());
|
||||
|
||||
var client = ProviderHelper.GetClient(_model, _services);
|
||||
var client = ProviderHelper.GetClient(Provider, _model, _services);
|
||||
|
||||
var completionsOptions = new CompletionsOptions()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue