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

52 lines
1.4 KiB
C#
Raw Normal View History

2023-10-09 22:28:17 +00:00
using Azure.AI.OpenAI;
using Azure;
using System;
using BotSharp.Plugin.AzureOpenAI.Settings;
using BotSharp.Abstraction.Conversations.Models;
using System.Collections.Generic;
namespace BotSharp.Plugin.AzureOpenAI.Providers;
public class ProviderHelper
{
2023-10-23 23:20:18 +00:00
public static OpenAIClient GetClient(string model, AzureOpenAiSettings settings)
2023-10-09 22:28:17 +00:00
{
2023-10-29 01:54:10 +00:00
if (model.Contains("gpt-4") || model.Contains("gpt4"))
2023-10-09 22:28:17 +00:00
{
var client = new OpenAIClient(new Uri(settings.GPT4.Endpoint), new AzureKeyCredential(settings.GPT4.ApiKey));
2023-10-23 23:20:18 +00:00
return client;
2023-10-09 22:28:17 +00:00
}
else
{
var client = new OpenAIClient(new Uri(settings.Endpoint), new AzureKeyCredential(settings.ApiKey));
2023-10-23 23:20:18 +00:00
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;
}
}