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