diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs new file mode 100644 index 00000000..f51e1941 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs @@ -0,0 +1,6 @@ +namespace BotSharp.Abstraction.Agents.Settings; + +public class AgentSettings +{ + public string DataDir { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs index f8a3ecae..04f3e2e4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs @@ -6,16 +6,16 @@ public class RoleDialogModel /// user, system, assistant /// public string Role { get; set; } - public string Text { get; set; } + public string Content { get; set; } public RoleDialogModel(string role, string text) { Role = role; - Text = text; + Content = text; } public override string ToString() { - return $"{Role}: {Text}"; + return $"{Role}: {Content}"; } } diff --git a/src/Infrastructure/BotSharp.Abstraction/MLTasks/IChatCompletion.cs b/src/Infrastructure/BotSharp.Abstraction/MLTasks/IChatCompletion.cs index 00ef6c7e..91dea670 100644 --- a/src/Infrastructure/BotSharp.Abstraction/MLTasks/IChatCompletion.cs +++ b/src/Infrastructure/BotSharp.Abstraction/MLTasks/IChatCompletion.cs @@ -4,5 +4,6 @@ namespace BotSharp.Abstraction.MLTasks; public interface IChatCompletion { - Task GetChatCompletionsAsync(Agent agent, List conversations); + string GetChatCompletions(Agent agent, List conversations); + Task GetChatCompletionsStreamingAsync(Agent agent, List conversations); } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs index 8f1e70c6..0d9c21db 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs @@ -6,7 +6,7 @@ public partial class AgentService { public async Task CreateAgent(Agent agent) { - var db = _services.GetRequiredService(); + var db = _services.GetRequiredService(); var record = db.Agent.FirstOrDefault(x => x.OwnerId == _user.Id && x.Name == agent.Name); if (record != null) { @@ -19,9 +19,9 @@ public partial class AgentService record.CreatedDateTime = DateTime.UtcNow; record.UpdatedDateTime = DateTime.UtcNow; - db.Transaction(delegate + db.Transaction(delegate { - db.Add(record); + db.Add(record); }); return record.ToAgent(); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs index cdbdf95b..27b5a2cf 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs @@ -7,7 +7,7 @@ public partial class AgentService { public async Task> GetAgents() { - var db = _services.GetRequiredService(); + var db = _services.GetRequiredService(); var query = from agent in db.Agent where agent.OwnerId == _user.Id select agent.ToAgent(); @@ -16,7 +16,7 @@ public partial class AgentService public async Task GetAgent(string id) { - var db = _services.GetRequiredService(); + var db = _services.GetRequiredService(); var query = from agent in db.Agent where agent.Id == id select agent.ToAgent(); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index 4f10598c..25723fcc 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -7,9 +7,9 @@ public partial class AgentService { public async Task UpdateAgent(Agent agent) { - var db = _services.GetRequiredService(); + var db = _services.GetRequiredService(); - db.Transaction(delegate + db.Transaction(delegate { var record = db.Agent.FirstOrDefault(x => x.OwnerId == agent.OwerId && x.Id == agent.Id); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs index 6a53d291..55238f8d 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs @@ -6,16 +6,18 @@ public partial class AgentService : IAgentService { private readonly IServiceProvider _services; private readonly IUserIdentity _user; + private readonly AgentSettings _settings; - public AgentService(IServiceProvider services, IUserIdentity user) + public AgentService(IServiceProvider services, IUserIdentity user, AgentSettings settings) { _services = services; _user = user; + _settings = settings; } public string GetAgentDataDir(string agentId) { - var dir = Path.Combine("data", agentId); + var dir = Path.Combine(_settings.DataDir, agentId); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); diff --git a/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs b/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs index 35ee23b2..cb8a3545 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs +++ b/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs @@ -1,4 +1,3 @@ -using BotSharp.Abstraction.Conversations.Settings; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; @@ -13,6 +12,10 @@ public static class BotSharpServiceCollectionExtensions services.AddScoped(); + var agentSettings = new AgentSettings(); + config.Bind("Agent", agentSettings); + services.AddSingleton((IServiceProvider x) => agentSettings); + var convsationSettings = new ConversationSetting(); config.Bind("Conversation", convsationSettings); services.AddSingleton((IServiceProvider x) => convsationSettings); @@ -20,15 +23,29 @@ public static class BotSharpServiceCollectionExtensions services.AddScoped(); services.AddScoped(); - RegisterRepository(services, config); - RegisterPlugins(services, config); return services; } - public static void ConfigureBotSharp(this IServiceCollection services) + public static IServiceCollection ConfigureBotSharpRepository(this IServiceCollection services, IConfiguration config) + where Tdb : DataContext { + var databaseSettings = new DatabaseSettings(); + config.Bind("Database", databaseSettings); + services.AddSingleton((IServiceProvider x) => databaseSettings); + + var myDatabaseSettings = new MyDatabaseSettings(); + config.Bind("Database", myDatabaseSettings); + services.AddSingleton((IServiceProvider x) => databaseSettings); + + services.AddScoped((IServiceProvider x) + => DataContextHelper.GetDbContext(myDatabaseSettings, x)); + + services.AddScoped((IServiceProvider x) + => DataContextHelper.GetDbContext(myDatabaseSettings, x)); + + return services; } public static IApplicationBuilder UseBotSharp(this IApplicationBuilder app) @@ -43,27 +60,6 @@ public static class BotSharpServiceCollectionExtensions return app; } - public static void RegisterRepository(IServiceCollection services, IConfiguration config) - { - var databaseSettings = new DatabaseSettings(); - config.Bind("Database", databaseSettings); - services.AddSingleton((IServiceProvider x) => databaseSettings); - - var myDatabaseSettings = new MyDatabaseSettings(); - config.Bind("Database", myDatabaseSettings); - services.AddSingleton((IServiceProvider x) => databaseSettings); - - services.AddScoped((IServiceProvider x) => - { - return DataContextHelper.GetDbContext(myDatabaseSettings, x); - }); - - services.AddScoped((IServiceProvider x) => - { - return DataContextHelper.GetDbContext(myDatabaseSettings, x); - }); - } - public static void RegisterPlugins(IServiceCollection services, IConfiguration config) { var pluginSettings = new PluginLoaderSettings(); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index 9f89a15f..d07dc31f 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -30,7 +30,7 @@ public class ConversationService : IConversationService public async Task GetConversation(string id) { - var db = _services.GetRequiredService(); + var db = _services.GetRequiredService(); var query = from sess in db.Conversation where sess.Id == id orderby sess.CreatedTime descending @@ -40,7 +40,7 @@ public class ConversationService : IConversationService public async Task> GetConversations() { - var db = _services.GetRequiredService(); + var db = _services.GetRequiredService(); var query = from sess in db.Conversation where sess.UserId == _user.Id orderby sess.CreatedTime descending @@ -50,16 +50,16 @@ public class ConversationService : IConversationService public async Task NewConversation(Conversation sess) { - var db = _services.GetRequiredService(); + var db = _services.GetRequiredService(); var record = ConversationRecord.FromConversation(sess); record.Id = sess.Id.IfNullOrEmptyAs(Guid.NewGuid().ToString()); record.UserId = sess.UserId.IfNullOrEmptyAs(_user.Id); record.Title = "New Conversation"; - db.Transaction(delegate + db.Transaction(delegate { - db.Add(record); + db.Add(record); }); _storage.InitStorage(sess.AgentId, record.Id); @@ -92,7 +92,7 @@ public class ConversationService : IConversationService agent.Knowledges = await knowledge.GetKnowledges(new KnowledgeRetrievalModel { AgentId = agentId, - Question = string.Join("\n", wholeDialogs.Select(x => x.Text)) + Question = string.Join("\n", wholeDialogs.Select(x => x.Content)) }); } @@ -110,7 +110,7 @@ public class ConversationService : IConversationService .BeforeCompletion(); }); - var response = await chatCompletion.GetChatCompletionsAsync(agent, wholeDialogs); + var response = await chatCompletion.GetChatCompletionsStreamingAsync(agent, wholeDialogs); // After chat completion hook hooks.ForEach(async hook => diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs index 34d8f7a3..fc9564f9 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs @@ -14,7 +14,7 @@ public class ConversationStorage : IConversationStorage public void Append(string agentId, string conversationId, RoleDialogModel dialog) { var conversationFile = GetStorageFile(agentId, conversationId); - File.AppendAllText(conversationFile, $"{dialog.Role}: {dialog.Text}\n"); + File.AppendAllText(conversationFile, $"{dialog.Role}: {dialog.Content}\n"); } public List GetDialogs(string agentId, string conversationId) diff --git a/src/Infrastructure/BotSharp.Core/Plugins/LLamaSharp/ChatCompletionProvider.cs b/src/Infrastructure/BotSharp.Core/Plugins/LLamaSharp/ChatCompletionProvider.cs index edf9b217..35cdc80f 100644 --- a/src/Infrastructure/BotSharp.Core/Plugins/LLamaSharp/ChatCompletionProvider.cs +++ b/src/Infrastructure/BotSharp.Core/Plugins/LLamaSharp/ChatCompletionProvider.cs @@ -14,10 +14,15 @@ public class ChatCompletionProvider : IChatCompletion _services = services; } - public Task GetChatCompletionsAsync(Agent agent, List conversations) + public string GetChatCompletions(Agent agent, List conversations) + { + throw new NotImplementedException(); + } + + public Task GetChatCompletionsStreamingAsync(Agent agent, List conversations) { string totalResponse = ""; - var content = string.Join("\n", conversations.Select(x => $"{x.Role}: {x.Text.Replace("user:", "")}")).Trim(); + var content = string.Join("\n", conversations.Select(x => $"{x.Role}: {x.Content.Replace("user:", "")}")).Trim(); content += "\nassistant: "; var llama = _services.GetRequiredService(); diff --git a/src/Infrastructure/BotSharp.Core/Repository/Abstraction/IAgentTable.cs b/src/Infrastructure/BotSharp.Core/Repository/Abstraction/IBotSharpTable.cs similarity index 62% rename from src/Infrastructure/BotSharp.Core/Repository/Abstraction/IAgentTable.cs rename to src/Infrastructure/BotSharp.Core/Repository/Abstraction/IBotSharpTable.cs index 053aab71..2ea3383f 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/Abstraction/IAgentTable.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/Abstraction/IBotSharpTable.cs @@ -1,5 +1,5 @@ namespace BotSharp.Core.Repository.Abstraction; -public interface IAgentTable +public interface IBotSharpTable { } diff --git a/src/Infrastructure/BotSharp.Core/Repository/AgentDbContext.cs b/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs similarity index 85% rename from src/Infrastructure/BotSharp.Core/Repository/AgentDbContext.cs rename to src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs index a7dcdd31..98fa8eeb 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/AgentDbContext.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs @@ -1,6 +1,6 @@ namespace BotSharp.Core.Repository; -public class AgentDbContext : Database +public class BotSharpDbContext : Database { public IQueryable User => Table(); public IQueryable Agent => Table(); diff --git a/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs b/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs index 1b30a92d..4fa85feb 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs @@ -1,14 +1,14 @@ -using BotSharp.Core.Repository.Abstraction; -using EntityFrameworkCore.BootKit; using Microsoft.Data.SqlClient; +using MySqlConnector; using System.Data.Common; namespace BotSharp.Core.Repository; public static class DataContextHelper { - public static T GetDbContext(MyDatabaseSettings settings, IServiceProvider serviceProvider) + public static T GetDbContext(MyDatabaseSettings settings, IServiceProvider serviceProvider) where T : Database, new() + where Tdb : DataContext { if (settings.Assemblies == null) throw new Exception("Please set assemblies."); @@ -25,17 +25,33 @@ public static class DataContextHelper IsRelational = false }); } - else if (typeof(T) == typeof(AgentDbContext)) + else if (typeof(T) == typeof(BotSharpDbContext)) { - dc.BindDbContext(new DatabaseBind + if (typeof(Tdb).Name.StartsWith("DbContext4SqlServer")) { - ServiceProvider = serviceProvider, - MasterConnection = new SqlConnection(settings.BotSharp.Master), - SlaveConnections = settings.BotSharp.Slavers.Length == 0 ? - new List { new SqlConnection(settings.BotSharp.Master) } : - settings.BotSharp.Slavers.Select(x => new SqlConnection(x) as DbConnection).ToList(), - CreateDbIfNotExist = true - }); + dc.BindDbContext(new DatabaseBind + { + ServiceProvider = serviceProvider, + MasterConnection = new SqlConnection(settings.BotSharp.Master), + SlaveConnections = settings.BotSharp.Slavers.Length == 0 ? + new List { new SqlConnection(settings.BotSharp.Master) } : + settings.BotSharp.Slavers.Select(x => new SqlConnection(x) as DbConnection) + .ToList(), + CreateDbIfNotExist = true + }); + } + else if (typeof(Tdb).Name.StartsWith("DbContext4Aurora") || + typeof(Tdb).Name.StartsWith("DbContext4MySql")) + { + dc.BindDbContext(new DatabaseBind + { + ServiceProvider = serviceProvider, + MasterConnection = new MySqlConnection(settings.BotSharp.Master), + SlaveConnections = settings.BotSharp.Slavers + .Select(x => new MySqlConnection(x) as DbConnection).ToList(), + CreateDbIfNotExist = true + }); + } } return dc; } diff --git a/src/Infrastructure/BotSharp.Core/Repository/DbTables/AgentRecord.cs b/src/Infrastructure/BotSharp.Core/Repository/DbTables/AgentRecord.cs index eb5e3f42..99fd31b3 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/DbTables/AgentRecord.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/DbTables/AgentRecord.cs @@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace BotSharp.Core.Repository.DbTables; [Table("Agent")] -public class AgentRecord : DbRecord, IAgentTable +public class AgentRecord : DbRecord, IBotSharpTable { [Required] [MaxLength(64)] diff --git a/src/Infrastructure/BotSharp.Core/Repository/DbTables/ConversationRecord.cs b/src/Infrastructure/BotSharp.Core/Repository/DbTables/ConversationRecord.cs index a3b75cc2..167f664d 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/DbTables/ConversationRecord.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/DbTables/ConversationRecord.cs @@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace BotSharp.Core.Repository.DbTables; [Table("Conversation")] -public class ConversationRecord : DbRecord, IAgentTable +public class ConversationRecord : DbRecord, IBotSharpTable { [Required] [MaxLength(36)] diff --git a/src/Infrastructure/BotSharp.Core/Repository/DbTables/UserRecord.cs b/src/Infrastructure/BotSharp.Core/Repository/DbTables/UserRecord.cs index ab357436..88d8b51c 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/DbTables/UserRecord.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/DbTables/UserRecord.cs @@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace BotSharp.Core.Repository.DbTables; [Table("User")] -public class UserRecord : DbRecord, IAgentTable +public class UserRecord : DbRecord, IBotSharpTable { [Required] [MaxLength(64)] diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 6acdf0f5..9d979168 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -23,7 +23,7 @@ public class UserService : IUserService public async Task CreateUser(User user) { - var db = _services.GetRequiredService(); + var db = _services.GetRequiredService(); var record = db.User.FirstOrDefault(x => x.Email == user.Email.ToLower()); if (record != null) { @@ -36,9 +36,9 @@ public class UserService : IUserService record.Salt = Guid.NewGuid().ToString("N"); record.Password = Utilities.HashText(user.Password, record.Salt); - db.Transaction(delegate + db.Transaction(delegate { - db.Add(record); + db.Add(record); }); return record.ToUser(); @@ -49,7 +49,7 @@ public class UserService : IUserService var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization)); var (userEmail, password) = base64.SplitAsTuple(":"); - var db = _services.GetRequiredService(); + var db = _services.GetRequiredService(); var record = db.User.FirstOrDefault(x => x.Email == userEmail); if (record == null) { @@ -104,7 +104,7 @@ public class UserService : IUserService { var userId = _user.Id; - var db = _services.GetRequiredService(); + var db = _services.GetRequiredService(); var user = (from u in db.User where u.Id == userId select new User diff --git a/src/Infrastructure/BotSharp.Core/Using.cs b/src/Infrastructure/BotSharp.Core/Using.cs index 304bcf8c..45712028 100644 --- a/src/Infrastructure/BotSharp.Core/Using.cs +++ b/src/Infrastructure/BotSharp.Core/Using.cs @@ -18,4 +18,6 @@ global using BotSharp.Core.Agents.Services; global using BotSharp.Core.Conversations.Services; global using BotSharp.Core.Infrastructures; global using BotSharp.Core.Plugins; -global using BotSharp.Core.Users.Services; \ No newline at end of file +global using BotSharp.Core.Users.Services; +global using BotSharp.Abstraction.Agents.Settings; +global using BotSharp.Abstraction.Conversations.Settings; \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj b/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj index 3ce7d561..651612a6 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs index 22b8c2fc..b2a47a67 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs @@ -6,7 +6,6 @@ using BotSharp.Abstraction.MLTasks; using BotSharp.Plugin.AzureOpenAI.Settings; using System; using System.Collections.Generic; -using System.IO; using System.Threading.Tasks; namespace BotSharp.Plugin.AzureOpenAI.Providers; @@ -20,30 +19,25 @@ public class ChatCompletionProvider : IChatCompletion _settings = settings; } - /*public async Task GetChatCompletionsAsync(List conversations, - Func onChunkReceived) + public string GetChatCompletions(Agent agent, List conversations) { var client = new OpenAIClient(new Uri(_settings.Endpoint), new AzureKeyCredential(_settings.ApiKey)); - var chatCompletionsOptions = PrepareOptions(conversations); + var chatCompletionsOptions = PrepareOptions(agent, conversations); - var response = await client.GetChatCompletionsStreamingAsync(_settings.DeploymentModel.ChatCompletionModel, chatCompletionsOptions); - using StreamingChatCompletions streaming = response.Value; + var response = client.GetChatCompletions(_settings.DeploymentModel.ChatCompletionModel, chatCompletionsOptions); - string content = ""; - await foreach (var choice in streaming.GetChoicesStreaming()) + string output = ""; + foreach (var choice in response.Value.Choices) { - await foreach (var message in choice.GetMessageStreaming()) - { - if (message.Content == null) - continue; - Console.Write(message.Content); - content += message.Content; - await onChunkReceived(message.Content); - } + var message = choice.Message; + if (message.Content == null) + continue; + Console.Write(message.Content); + output += message.Content; } - Console.WriteLine(); - }*/ + return output.Trim(); + } public List GetChatSamples(string sampleText) { @@ -77,7 +71,7 @@ public class ChatCompletionProvider : IChatCompletion } - public async Task GetChatCompletionsAsync(Agent agent, List conversations) + public async Task GetChatCompletionsStreamingAsync(Agent agent, List conversations) { var client = new OpenAIClient(new Uri(_settings.Endpoint), new AzureKeyCredential(_settings.ApiKey)); var chatCompletionsOptions = PrepareOptions(agent, conversations); @@ -117,12 +111,12 @@ public class ChatCompletionProvider : IChatCompletion var samples = GetChatSamples(agent.Samples); foreach (var message in samples) { - chatCompletionsOptions.Messages.Add(new ChatMessage(message.Role, message.Text)); + chatCompletionsOptions.Messages.Add(new ChatMessage(message.Role, message.Content)); } foreach (var message in conversations) { - chatCompletionsOptions.Messages.Add(new ChatMessage(message.Role, message.Text)); + chatCompletionsOptions.Messages.Add(new ChatMessage(message.Role, message.Content)); } return chatCompletionsOptions; diff --git a/src/Plugins/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj b/src/Plugins/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj index 065c06ae..75da1f2c 100644 --- a/src/Plugins/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj +++ b/src/Plugins/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj @@ -8,7 +8,6 @@ - diff --git a/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs b/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs index 0337c983..6e7ad937 100644 --- a/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs +++ b/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System; -using Azure.AI.OpenAI; using BotSharp.Abstraction.ApiAdapters; using BotSharp.Plugin.ChatbotUI.ViewModels; using Microsoft.Extensions.DependencyInjection; @@ -94,7 +93,7 @@ public class ChatbotUiController : ControllerBase, IApiAdapter { new OpenAiChoice { - Delta = new ChatMessage(ChatRole.Assistant, content) + Delta = new RoleDialogModel("assistant", content) } } }; diff --git a/src/Plugins/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiChoice.cs b/src/Plugins/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiChoice.cs index a72510df..02bb4792 100644 --- a/src/Plugins/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiChoice.cs +++ b/src/Plugins/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiChoice.cs @@ -1,4 +1,4 @@ -using Azure.AI.OpenAI; +using BotSharp.Abstraction.Conversations.Models; using Newtonsoft.Json; using System.Text.Json.Serialization; @@ -9,5 +9,5 @@ public class OpenAiChoice [JsonPropertyName("finish_reason")] [JsonProperty("finish_reason")] public string FinishReason { get; set; } - public ChatMessage Delta { get; set; } + public RoleDialogModel Delta { get; set; } }