BotSharp/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ProviderHelper.cs

47 lines
1.3 KiB
C#
Raw Normal View History

2023-10-09 22:28:17 +00:00
using Azure.AI.OpenAI;
using Azure;
using System;
using BotSharp.Abstraction.Conversations.Models;
using System.Collections.Generic;
2023-12-13 18:12:25 +00:00
using Microsoft.Extensions.DependencyInjection;
using BotSharp.Abstraction.MLTasks;
2023-10-09 22:28:17 +00:00
namespace BotSharp.Plugin.AzureOpenAI.Providers;
public class ProviderHelper
{
2023-12-13 18:12:25 +00:00
public static OpenAIClient GetClient(string model, IServiceProvider services)
2023-10-09 22:28:17 +00:00
{
2023-12-13 18:12:25 +00:00
var settingsService = services.GetRequiredService<ILlmProviderSettingService>();
var settings = settingsService.GetSetting("azure-openai", model);
var client = new OpenAIClient(new Uri(settings.Endpoint), new AzureKeyCredential(settings.ApiKey));
return client;
2023-10-09 22:28:17 +00:00
}
2023-10-19 17:24:00 +00:00
public static List<RoleDialogModel> GetChatSamples(List<string> lines)
2023-10-09 22:28:17 +00:00
{
var samples = new List<RoleDialogModel>();
2023-10-19 17:24:00 +00:00
for (int i = 0; i < lines.Count; i++)
2023-10-09 22:28:17 +00:00
{
var line = lines[i];
if (string.IsNullOrEmpty(line.Trim()))
{
continue;
}
var role = line.Substring(0, line.IndexOf(' ') - 1).Trim();
var content = line.Substring(line.IndexOf(' ') + 1).Trim();
// comments
if (role == "##")
{
continue;
}
samples.Add(new RoleDialogModel(role, content));
}
return samples;
}
}