BotSharp/src/Plugins/BotSharp.Plugin.AzureOpenAI/Services/ChatCompletionService.cs
2023-06-22 23:43:00 -05:00

32 lines
848 B
C#

using Azure.AI.OpenAI;
using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Infrastructures.ContentTransmitters;
using BotSharp.Abstraction.MLTasks;
using BotSharp.Abstraction.Models;
using System.Threading.Tasks;
namespace BotSharp.Plugin.AzureOpenAI.Services;
public class ChatCompletionService : IChatServiceZone
{
private readonly IChatCompletion _chatCompletion;
public ChatCompletionService(IChatCompletion chatCompletion)
{
_chatCompletion = chatCompletion;
}
public int Priority => 100;
public async Task Serving(ContentContainer content)
{
var output = await _chatCompletion.GetChatCompletionsAsync(content.Conversations);
content.Output = new RoleDialogModel
{
Role = ChatRole.Assistant.ToString(),
Text = output
};
}
}