From b49a87abe00a6a91e789447bc563f9b94594b189 Mon Sep 17 00:00:00 2001 From: Kosta Petan Date: Thu, 6 Feb 2025 20:56:57 +0100 Subject: [PATCH] cleanup --- .../Agents/Conversation/Conversation.cs | 3 +- .../Agents/CustomerInfo/CustomerInfo.cs | 3 +- .../Agents/Discount/Discount.cs | 7 +- .../Agents/Dispatcher/Dispatcher.cs | 2 +- .../Agents/Invoice/Invoice.cs | 2 +- .../Agents/QnA/QnA.cs | 3 +- .../Agents/SignalR/SignalR.cs | 2 +- .../AgentConfiguration.cs | 20 ---- .../ConversationAgentConfiguration.cs | 17 --- .../CustomerInfoAgentConfiguration.cs | 22 ---- .../DiscountAgentConfiguration.cs | 16 --- .../DispatcherAgentConfiguration.cs | 16 --- .../IAgentConfiguration.cs | 11 -- .../InvoiceAgentConfiguration.cs | 17 --- .../QnAAgentConfiguration.cs | 16 --- .../SignalRAgentConfiguration.cs | 16 --- .../SupportCenter.ApiService/Consts.cs | 8 ++ .../Controllers/Interactions.cs | 1 - .../Data/CosmosDb/CosmosDbRepository.cs | 43 +++----- .../Data/CosmosDb/CustomerRepository.cs | 13 +-- .../Extensions/ServiceExtensions.cs | 99 ----------------- .../Options/AiSearchOptions.cs | 21 ---- .../Options/Consts.cs | 7 -- .../Options/CosmosDbContainerOptions.cs | 19 ---- .../Options/CosmosDbOptions.cs | 13 --- .../Options/OpenAIOptions.cs | 33 ------ .../Options/QdrantOptions.cs | 10 -- .../SupportCenter.ApiService/Program.cs | 10 +- .../SemanticKernel/Extensions.cs | 102 ------------------ .../SignalRHub/SupportCenterHub.cs | 2 +- 30 files changed, 43 insertions(+), 511 deletions(-) delete mode 100644 samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/AgentConfiguration.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/ConversationAgentConfiguration.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/CustomerInfoAgentConfiguration.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/DiscountAgentConfiguration.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/DispatcherAgentConfiguration.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/IAgentConfiguration.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/InvoiceAgentConfiguration.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/QnAAgentConfiguration.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/SignalRAgentConfiguration.cs create mode 100644 samples/support-center/SupportCenter.ApiService/Consts.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/Extensions/ServiceExtensions.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/Options/AiSearchOptions.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/Options/Consts.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/Options/CosmosDbContainerOptions.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/Options/CosmosDbOptions.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/Options/OpenAIOptions.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/Options/QdrantOptions.cs delete mode 100644 samples/support-center/SupportCenter.ApiService/SemanticKernel/Extensions.cs diff --git a/samples/support-center/SupportCenter.ApiService/Agents/Conversation/Conversation.cs b/samples/support-center/SupportCenter.ApiService/Agents/Conversation/Conversation.cs index 5e32d72..2f9a5e6 100644 --- a/samples/support-center/SupportCenter.ApiService/Agents/Conversation/Conversation.cs +++ b/samples/support-center/SupportCenter.ApiService/Agents/Conversation/Conversation.cs @@ -3,9 +3,8 @@ using Microsoft.Extensions.AI; using SupportCenter.ApiService.Events; using SupportCenter.ApiService.Extensions; -using SupportCenter.ApiService.Options; using SupportCenter.ApiService.SignalRHub; -using static SupportCenter.ApiService.Options.Consts; +using static SupportCenter.ApiService.Consts; namespace SupportCenter.ApiService.Agents.Conversation; [ImplicitStreamSubscription(OrleansNamespace)] diff --git a/samples/support-center/SupportCenter.ApiService/Agents/CustomerInfo/CustomerInfo.cs b/samples/support-center/SupportCenter.ApiService/Agents/CustomerInfo/CustomerInfo.cs index 4d270f0..ff6efbd 100644 --- a/samples/support-center/SupportCenter.ApiService/Agents/CustomerInfo/CustomerInfo.cs +++ b/samples/support-center/SupportCenter.ApiService/Agents/CustomerInfo/CustomerInfo.cs @@ -4,8 +4,7 @@ using SupportCenter.ApiService.Data.CosmosDb; using SupportCenter.ApiService.Events; using SupportCenter.ApiService.Extensions; -using SupportCenter.ApiService.Options; -using static SupportCenter.ApiService.Options.Consts; +using static SupportCenter.ApiService.Consts; namespace SupportCenter.ApiService.Agents.CustomerInfo; diff --git a/samples/support-center/SupportCenter.ApiService/Agents/Discount/Discount.cs b/samples/support-center/SupportCenter.ApiService/Agents/Discount/Discount.cs index aa79fd3..6ae2b21 100644 --- a/samples/support-center/SupportCenter.ApiService/Agents/Discount/Discount.cs +++ b/samples/support-center/SupportCenter.ApiService/Agents/Discount/Discount.cs @@ -2,17 +2,16 @@ using Microsoft.AI.Agents.Orleans; using Microsoft.Extensions.AI; using SupportCenter.ApiService.Events; -using SupportCenter.ApiService.Options; -using static SupportCenter.ApiService.Options.Consts; +using static SupportCenter.ApiService.Consts; namespace SupportCenter.ApiService.Agents.Discount; -[ImplicitStreamSubscription(Consts.OrleansNamespace)] +[ImplicitStreamSubscription(OrleansNamespace)] public class Discount : AiAgent { private readonly ILogger _logger; - protected override string Namespace => Consts.OrleansNamespace; + protected override string Namespace => OrleansNamespace; public Discount([PersistentState("state", "messages")] IPersistentState> state, ILogger logger, diff --git a/samples/support-center/SupportCenter.ApiService/Agents/Dispatcher/Dispatcher.cs b/samples/support-center/SupportCenter.ApiService/Agents/Dispatcher/Dispatcher.cs index 23c2e83..cd75d9d 100644 --- a/samples/support-center/SupportCenter.ApiService/Agents/Dispatcher/Dispatcher.cs +++ b/samples/support-center/SupportCenter.ApiService/Agents/Dispatcher/Dispatcher.cs @@ -5,7 +5,7 @@ using SupportCenter.ApiService.Events; using SupportCenter.ApiService.Extensions; using System.Reflection; -using static SupportCenter.ApiService.Options.Consts; +using static SupportCenter.ApiService.Consts; namespace SupportCenter.ApiService.Agents.Dispatcher; diff --git a/samples/support-center/SupportCenter.ApiService/Agents/Invoice/Invoice.cs b/samples/support-center/SupportCenter.ApiService/Agents/Invoice/Invoice.cs index ac87c95..7a6cd6c 100644 --- a/samples/support-center/SupportCenter.ApiService/Agents/Invoice/Invoice.cs +++ b/samples/support-center/SupportCenter.ApiService/Agents/Invoice/Invoice.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.AI; using SupportCenter.ApiService.Events; using SupportCenter.ApiService.Extensions; -using static SupportCenter.ApiService.Options.Consts; +using static SupportCenter.ApiService.Consts; namespace SupportCenter.ApiService.Agents.Invoice; diff --git a/samples/support-center/SupportCenter.ApiService/Agents/QnA/QnA.cs b/samples/support-center/SupportCenter.ApiService/Agents/QnA/QnA.cs index ea39a42..91d8625 100644 --- a/samples/support-center/SupportCenter.ApiService/Agents/QnA/QnA.cs +++ b/samples/support-center/SupportCenter.ApiService/Agents/QnA/QnA.cs @@ -3,8 +3,7 @@ using Microsoft.Extensions.AI; using SupportCenter.ApiService.Events; using SupportCenter.ApiService.Extensions; -using SupportCenter.ApiService.Options; -using static SupportCenter.ApiService.Options.Consts; +using static SupportCenter.ApiService.Consts; namespace SupportCenter.ApiService.Agents.QnA; [ImplicitStreamSubscription(OrleansNamespace)] diff --git a/samples/support-center/SupportCenter.ApiService/Agents/SignalR/SignalR.cs b/samples/support-center/SupportCenter.ApiService/Agents/SignalR/SignalR.cs index 1d64ca3..afb861c 100644 --- a/samples/support-center/SupportCenter.ApiService/Agents/SignalR/SignalR.cs +++ b/samples/support-center/SupportCenter.ApiService/Agents/SignalR/SignalR.cs @@ -4,7 +4,7 @@ using SupportCenter.ApiService.Extensions; using SupportCenter.ApiService.SignalRHub; using System.Collections.Concurrent; -using static SupportCenter.ApiService.Options.Consts; +using static SupportCenter.ApiService.Consts; namespace SupportCenter.ApiService.Agents.SignalR; diff --git a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/AgentConfiguration.cs b/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/AgentConfiguration.cs deleted file mode 100644 index f2a429d..0000000 --- a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/AgentConfiguration.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace SupportCenter.ApiService.AgentsConfigurationFactory -{ - public static class AgentConfiguration - { - public static IAgentConfiguration GetAgentConfiguration(string agent) - { - return agent switch - { - "Invoice" => new InvoiceAgentConfiguration(), - "Conversation" => new ConversationAgentConfiguration(), - "CustomerInfo" => new CustomerInfoAgentConfiguration(), - "QnA" => new QnAAgentConfiguration(), - "Dispatcher" => new DispatcherAgentConfiguration(), - "Discount" => new DiscountAgentConfiguration(), - "SignalR" => new SignalRAgentConfiguration(), - _ => throw new ArgumentException("Unsupported agent type", nameof(agent)), - }; - } - } -} diff --git a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/ConversationAgentConfiguration.cs b/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/ConversationAgentConfiguration.cs deleted file mode 100644 index 4ab68cd..0000000 --- a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/ConversationAgentConfiguration.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.SemanticKernel; -using SupportCenter.ApiService.Options; - -namespace SupportCenter.ApiService.AgentsConfigurationFactory -{ - public class ConversationAgentConfiguration : IAgentConfiguration - { - public void ConfigureOpenAI(OpenAIOptions options) - { - options.ChatDeploymentOrModelId = options.ConversationDeploymentOrModelId ?? options.ChatDeploymentOrModelId; - } - - public void ConfigureKernel(Kernel kernel, IServiceProvider serviceProvider) - { - } - } -} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/CustomerInfoAgentConfiguration.cs b/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/CustomerInfoAgentConfiguration.cs deleted file mode 100644 index 547da60..0000000 --- a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/CustomerInfoAgentConfiguration.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.SemanticKernel; -using SupportCenter.ApiService.Options; -using SupportCenter.ApiService.SemanticKernel.Plugins.CustomerPlugin; - -namespace SupportCenter.ApiService.AgentsConfigurationFactory -{ - public class CustomerInfoAgentConfiguration : IAgentConfiguration - { - private readonly string customerPlugin = "CustomerPlugin"; - - public void ConfigureOpenAI(OpenAIOptions options) - { - options.ChatDeploymentOrModelId = options.ConversationDeploymentOrModelId ?? options.ChatDeploymentOrModelId; - } - - public void ConfigureKernel(Kernel kernel, IServiceProvider serviceProvider) - { - if (kernel.Plugins.TryGetPlugin(customerPlugin, out _) == false) - kernel.ImportPluginFromObject(serviceProvider.GetRequiredService(), customerPlugin); - } - } -} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/DiscountAgentConfiguration.cs b/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/DiscountAgentConfiguration.cs deleted file mode 100644 index be855f4..0000000 --- a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/DiscountAgentConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.SemanticKernel; -using SupportCenter.ApiService.Options; - -namespace SupportCenter.ApiService.AgentsConfigurationFactory -{ - internal class DiscountAgentConfiguration : IAgentConfiguration - { - public void ConfigureOpenAI(OpenAIOptions options) - { - } - - public void ConfigureKernel(Kernel kernel, IServiceProvider serviceProvider) - { - } - } -} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/DispatcherAgentConfiguration.cs b/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/DispatcherAgentConfiguration.cs deleted file mode 100644 index bd18893..0000000 --- a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/DispatcherAgentConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.SemanticKernel; -using SupportCenter.ApiService.Options; - -namespace SupportCenter.ApiService.AgentsConfigurationFactory -{ - internal class DispatcherAgentConfiguration : IAgentConfiguration - { - public void ConfigureOpenAI(OpenAIOptions options) - { - } - - public void ConfigureKernel(Kernel kernel, IServiceProvider serviceProvider) - { - } - } -} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/IAgentConfiguration.cs b/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/IAgentConfiguration.cs deleted file mode 100644 index e36efee..0000000 --- a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/IAgentConfiguration.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.SemanticKernel; -using SupportCenter.ApiService.Options; - -namespace SupportCenter.ApiService.AgentsConfigurationFactory -{ - public interface IAgentConfiguration - { - void ConfigureOpenAI(OpenAIOptions options); - void ConfigureKernel(Kernel kernel, IServiceProvider serviceProvider); - } -} diff --git a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/InvoiceAgentConfiguration.cs b/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/InvoiceAgentConfiguration.cs deleted file mode 100644 index bf69d4e..0000000 --- a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/InvoiceAgentConfiguration.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.SemanticKernel; -using SupportCenter.ApiService.Options; - -namespace SupportCenter.ApiService.AgentsConfigurationFactory -{ - public class InvoiceAgentConfiguration : IAgentConfiguration - { - public void ConfigureOpenAI(OpenAIOptions options) - { - options.ChatDeploymentOrModelId = options.InvoiceDeploymentOrModelId ?? options.ChatDeploymentOrModelId; - } - - public void ConfigureKernel(Kernel kernel, IServiceProvider serviceProvider) - { - } - } -} diff --git a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/QnAAgentConfiguration.cs b/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/QnAAgentConfiguration.cs deleted file mode 100644 index 4474b1f..0000000 --- a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/QnAAgentConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.SemanticKernel; -using SupportCenter.ApiService.Options; - -namespace SupportCenter.ApiService.AgentsConfigurationFactory -{ - internal class QnAAgentConfiguration : IAgentConfiguration - { - public void ConfigureOpenAI(OpenAIOptions options) - { - } - - public void ConfigureKernel(Kernel kernel, IServiceProvider serviceProvider) - { - } - } -} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/SignalRAgentConfiguration.cs b/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/SignalRAgentConfiguration.cs deleted file mode 100644 index 1168148..0000000 --- a/samples/support-center/SupportCenter.ApiService/AgentsConfigurationFactory/SignalRAgentConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.SemanticKernel; -using SupportCenter.ApiService.Options; - -namespace SupportCenter.ApiService.AgentsConfigurationFactory -{ - internal class SignalRAgentConfiguration : IAgentConfiguration - { - public void ConfigureOpenAI(OpenAIOptions options) - { - } - - public void ConfigureKernel(Kernel kernel, IServiceProvider serviceProvider) - { - } - } -} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/Consts.cs b/samples/support-center/SupportCenter.ApiService/Consts.cs new file mode 100644 index 0000000..898e514 --- /dev/null +++ b/samples/support-center/SupportCenter.ApiService/Consts.cs @@ -0,0 +1,8 @@ +namespace SupportCenter.ApiService +{ + public static class Consts + { + public const string OrleansNamespace = "SupportCenter"; + public const string Gpt4oMini = "gpt-4o-mini"; + } +} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/Controllers/Interactions.cs b/samples/support-center/SupportCenter.ApiService/Controllers/Interactions.cs index c44231b..039048d 100644 --- a/samples/support-center/SupportCenter.ApiService/Controllers/Interactions.cs +++ b/samples/support-center/SupportCenter.ApiService/Controllers/Interactions.cs @@ -1,7 +1,6 @@ using Microsoft.AI.Agents.Abstractions; using Microsoft.AspNetCore.Mvc; using SupportCenter.ApiService.Events; -using SupportCenter.ApiService.Options; namespace SupportCenter.ApiService.Controllers { diff --git a/samples/support-center/SupportCenter.ApiService/Data/CosmosDb/CosmosDbRepository.cs b/samples/support-center/SupportCenter.ApiService/Data/CosmosDb/CosmosDbRepository.cs index 1057e64..91641d6 100644 --- a/samples/support-center/SupportCenter.ApiService/Data/CosmosDb/CosmosDbRepository.cs +++ b/samples/support-center/SupportCenter.ApiService/Data/CosmosDb/CosmosDbRepository.cs @@ -1,48 +1,34 @@ using Microsoft.Azure.Cosmos; using SupportCenter.ApiService.Data.Entities; -using SupportCenter.ApiService.Options; namespace SupportCenter.ApiService.Data.CosmosDb { - public abstract class CosmosDbRepository - where TEntity : Entity - where TOptions : CosmosDbOptions + public abstract class CosmosDbRepository(CosmosClient client, ILogger> logger) + where T : Entity { - protected readonly ILogger Logger; - protected readonly Container Container; - - protected CosmosDbRepository(TOptions options, ILogger logger) + protected Container GetContainer() { - Logger = logger; - CosmosDbOptions configuration = options; - - var containerConfiguration = configuration.Containers?.FirstOrDefault(c => c.EntityName == typeof(TEntity).Name) - ?? throw new InvalidOperationException($"Container configuration for {typeof(TEntity).Name} not found."); - - var client = new CosmosClient(configuration.AccountUri, configuration.AccountKey); - client.CreateDatabaseIfNotExistsAsync(containerConfiguration.DatabaseName); - - var database = client.GetDatabase(containerConfiguration.DatabaseName); - database.CreateContainerIfNotExistsAsync(containerConfiguration.ContainerName, containerConfiguration.PartitionKey ?? "/partitionKey"); - - Container = database.GetContainer(containerConfiguration.ContainerName); + var database = client.GetDatabase("supportcenter"); + var container = database.GetContainer("items"); + return container; } - public async Task GetItemAsync(string id, string partitionKey) { - TOutput item = await Container.ReadItemAsync(id: id, partitionKey: new PartitionKey(partitionKey)); + var container = GetContainer(); + TOutput item = await container.ReadItemAsync(id: id, partitionKey: new PartitionKey(partitionKey)); return item; } - public async Task InsertItemAsync(TEntity entity) + public async Task InsertItemAsync(T entity) { try { - var response = await Container.CreateItemAsync(entity, new PartitionKey(entity.GetPartitionKeyValue())); + var container = GetContainer(); + var response = await container.CreateItemAsync(entity, new PartitionKey(entity.GetPartitionKeyValue())); } catch (Exception ex) { - Logger.LogCritical( + logger.LogCritical( ex, "An error occurred. MethodName: {methodName} ErrorMessage: {errorMessage}", nameof(InsertItemAsync), @@ -53,9 +39,10 @@ public async Task InsertItemAsync(TEntity entity) } } - public async Task UpsertItemAsync(TEntity entity) + public async Task UpsertItemAsync(T entity) { - await Container.UpsertItemAsync(entity, new PartitionKey(entity.GetPartitionKeyValue())); + var container = GetContainer(); + await container.UpsertItemAsync(entity, new PartitionKey(entity.GetPartitionKeyValue())); } } } diff --git a/samples/support-center/SupportCenter.ApiService/Data/CosmosDb/CustomerRepository.cs b/samples/support-center/SupportCenter.ApiService/Data/CosmosDb/CustomerRepository.cs index 1822da6..c90ef28 100644 --- a/samples/support-center/SupportCenter.ApiService/Data/CosmosDb/CustomerRepository.cs +++ b/samples/support-center/SupportCenter.ApiService/Data/CosmosDb/CustomerRepository.cs @@ -1,20 +1,16 @@ using Microsoft.Azure.Cosmos; -using Microsoft.Extensions.Options; using SupportCenter.ApiService.Data.CosmosDb.Entities; -using SupportCenter.ApiService.Options; namespace SupportCenter.ApiService.Data.CosmosDb { - public class CustomerRepository : CosmosDbRepository, ICustomerRepository + public class CustomerRepository(CosmosClient client, ILogger logger) : CosmosDbRepository(client,logger), ICustomerRepository { - public CustomerRepository(IOptions options, ILogger logger) - : base(options.Value, logger) { } - public async Task GetCustomerByIdAsync(string customerId) { + var container = GetContainer(); var query = new QueryDefinition("SELECT * FROM c WHERE c.id = @customerId") .WithParameter("@customerId", customerId); - var iterator = Container.GetItemQueryIterator(query); + var iterator = container.GetItemQueryIterator(query); Customer? customer = null; while (iterator.HasMoreResults) { @@ -26,8 +22,9 @@ public CustomerRepository(IOptions options, ILogger> GetCustomersAsync() { + var container = GetContainer(); var query = new QueryDefinition("SELECT * FROM c"); - var iterator = Container.GetItemQueryIterator(query); + var iterator = container.GetItemQueryIterator(query); var customers = new List(); while (iterator.HasMoreResults) { diff --git a/samples/support-center/SupportCenter.ApiService/Extensions/ServiceExtensions.cs b/samples/support-center/SupportCenter.ApiService/Extensions/ServiceExtensions.cs deleted file mode 100644 index 7e37099..0000000 --- a/samples/support-center/SupportCenter.ApiService/Extensions/ServiceExtensions.cs +++ /dev/null @@ -1,99 +0,0 @@ -using SupportCenter.ApiService.Data.CosmosDb; -using SupportCenter.ApiService.Options; -using SupportCenter.ApiService.SemanticKernel.Plugins.CustomerPlugin; -using static SupportCenter.ApiService.SemanticKernel.Extensions; - -namespace SupportCenter.ApiService.Extensions -{ - public static class ServiceCollectionExtensions - { - public static IServiceCollection ExtendOptions(this IServiceCollection services) - { - services.AddOptions() - .Configure((settings, configuration) => - { - configuration.GetSection(nameof(OpenAIOptions)).Bind(settings); - }) - .ValidateDataAnnotations() - .ValidateOnStart(); - - services.AddOptions() - .Configure((settings, configuration) => - { - configuration.GetSection(nameof(QdrantOptions)).Bind(settings); - }) - .ValidateDataAnnotations() - .ValidateOnStart(); - - services.AddOptions() - .Configure((settings, configuration) => - { - configuration.GetSection(nameof(CosmosDbOptions)).Bind(settings); - }) - .ValidateDataAnnotations() - .ValidateOnStart(); - - services.AddOptions() - .Configure((settings, configuration) => - { - configuration.GetSection(nameof(AISearchOptions)).Bind(settings); - }) - .ValidateDataAnnotations() - .ValidateOnStart(); - - return services; - } - - public static IServiceCollection ExtendServices(this IServiceCollection services) - { - RegisterRepositories(services); - AddSemanticKernelResolvers(services); - AddSemanticKernelServices(services); - return services; - } - - private static void AddSemanticKernelServices(IServiceCollection services) - { - services.AddKeyedSingleton("ConversationKernel", (sp, _) => CreateKernel(sp, "Conversation")); - services.AddKeyedSingleton("CustomerInfoKernel", (sp, _) => CreateKernel(sp, "CustomerInfo")); - services.AddKeyedSingleton("DispatcherKernel", (sp, _) => CreateKernel(sp, "Dispatcher")); - services.AddKeyedSingleton("InvoiceKernel", (sp, _) => CreateKernel(sp, "Invoice")); - services.AddKeyedSingleton("DiscountKernel", (sp, _) => CreateKernel(sp, "Discount")); - services.AddKeyedSingleton("QnAKernel", (sp, _) => CreateKernel(sp, "QnA")); - - services.AddKeyedSingleton("ConversationMemory", (sp, _) => CreateMemory(sp, "Conversation")); - services.AddKeyedSingleton("CustomerInfoMemory", (sp, _) => CreateMemory(sp, "CustomerInfo")); - services.AddKeyedSingleton("DispatcherMemory", (sp, _) => CreateMemory(sp, "Dispatcher")); - services.AddKeyedSingleton("InvoiceMemory", (sp, _) => CreateMemory(sp, "Invoice")); - services.AddKeyedSingleton("DiscountMemory", (sp, _) => CreateMemory(sp, "Discount")); - services.AddKeyedSingleton("QnAMemory", (sp, _) => CreateMemory(sp, "QnA")); - } - - private static void RegisterRepositories(IServiceCollection services) - { - services.AddSingleton(); - } - - private static void AddSemanticKernelResolvers(IServiceCollection services) - { - /* - * Register the resolvers for the Semantic Kernel - * This is used to resolve the kernel and memory for the agent - * The kernel is used to execute the functions and the memory is used to store the state - */ - //services.AddSingleton(serviceProvider => agent => - //{ - // return CreateKernel(serviceProvider, agent); - //}); - //services.AddSingleton(serviceProvider => agent => - //{ - // return CreateMemory(serviceProvider, agent); - //}); - } - - public static void RegisterSemanticKernelNativeFunctions(this IServiceCollection serviceCollection) - { - serviceCollection.AddSingleton(); - } - } -} diff --git a/samples/support-center/SupportCenter.ApiService/Options/AiSearchOptions.cs b/samples/support-center/SupportCenter.ApiService/Options/AiSearchOptions.cs deleted file mode 100644 index e5961a4..0000000 --- a/samples/support-center/SupportCenter.ApiService/Options/AiSearchOptions.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace SupportCenter.ApiService.Options; - -public class AISearchOptions -{ - // AI Search - [Required] - public string SearchEndpoint { get; set; } - [Required] - public string SearchKey { get; set; } - [Required] - public string SearchIndex { get; set; } - // Embeddings - [Required] - public string SearchEmbeddingDeploymentOrModelId { get; set; } - [Required] - public string SearchEmbeddingEndpoint { get; set; } - [Required] - public string SearchEmbeddingApiKey { get; set; } -} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/Options/Consts.cs b/samples/support-center/SupportCenter.ApiService/Options/Consts.cs deleted file mode 100644 index 3cba5e3..0000000 --- a/samples/support-center/SupportCenter.ApiService/Options/Consts.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SupportCenter.ApiService.Options; - -public static class Consts -{ - public const string OrleansNamespace = "SupportCenter"; - public const string Gpt4oMini = "gpt-4o-mini"; -} diff --git a/samples/support-center/SupportCenter.ApiService/Options/CosmosDbContainerOptions.cs b/samples/support-center/SupportCenter.ApiService/Options/CosmosDbContainerOptions.cs deleted file mode 100644 index 995bf69..0000000 --- a/samples/support-center/SupportCenter.ApiService/Options/CosmosDbContainerOptions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace SupportCenter.ApiService.Options -{ - public class CosmosDbContainerOptions - { - [Required] - public string? DatabaseName { get; set; } - - [Required] - public string? ContainerName { get; set; } - - [Required] - public string? PartitionKey { get; set; } - - [Required] - public string? EntityName { get; set; } - } -} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/Options/CosmosDbOptions.cs b/samples/support-center/SupportCenter.ApiService/Options/CosmosDbOptions.cs deleted file mode 100644 index da1d859..0000000 --- a/samples/support-center/SupportCenter.ApiService/Options/CosmosDbOptions.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace SupportCenter.ApiService.Options -{ - public class CosmosDbOptions - { - public string? AccountUri { get; set; } - - public string? AccountKey { get; set; } - - public IEnumerable? Containers { get; set; } - } -} diff --git a/samples/support-center/SupportCenter.ApiService/Options/OpenAIOptions.cs b/samples/support-center/SupportCenter.ApiService/Options/OpenAIOptions.cs deleted file mode 100644 index df8b784..0000000 --- a/samples/support-center/SupportCenter.ApiService/Options/OpenAIOptions.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace SupportCenter.ApiService.Options; - -public class OpenAIOptions -{ - // Embeddings - [Required] - public string EmbeddingsEndpoint { get; set; } = string.Empty; - [Required] - public string EmbeddingsApiKey { get; set; } = string.Empty; - [Required] - public string EmbeddingsDeploymentOrModelId { get; set; } = string.Empty; - - // Chat - [Required] - public string ChatEndpoint { get; set; } = string.Empty; - [Required] - public string ChatApiKey { get; set; } = string.Empty; - [Required] - public string ChatDeploymentOrModelId { get; set; } = string.Empty; - - public string? InvoiceDeploymentOrModelId { get; set; } - public string? ConversationDeploymentOrModelId { get; set; } - - // TextToImage - /*[Required] - public string? ImageEndpoint { get; set; } - [Required] - public string? ImageApiKey { get; set; } - // When using OpenAI, this is not required. - public string? ImageDeploymentOrModelId { get; set; }*/ -} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/Options/QdrantOptions.cs b/samples/support-center/SupportCenter.ApiService/Options/QdrantOptions.cs deleted file mode 100644 index c2ff57b..0000000 --- a/samples/support-center/SupportCenter.ApiService/Options/QdrantOptions.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace SupportCenter.ApiService.Options; -public class QdrantOptions -{ - [Required] - public string Endpoint { get; set; } = string.Empty; - [Required] - public int VectorSize { get; set; } -} \ No newline at end of file diff --git a/samples/support-center/SupportCenter.ApiService/Program.cs b/samples/support-center/SupportCenter.ApiService/Program.cs index e85c6f2..30229fa 100644 --- a/samples/support-center/SupportCenter.ApiService/Program.cs +++ b/samples/support-center/SupportCenter.ApiService/Program.cs @@ -3,7 +3,9 @@ using SupportCenter.ApiService.SignalRHub; using System.Text.Json; using Orleans.Serialization; -using static SupportCenter.ApiService.Options.Consts; +using SupportCenter.ApiService.Data.CosmosDb; +using SupportCenter.ApiService.SemanticKernel.Plugins.CustomerPlugin; +using static SupportCenter.ApiService.Consts; var builder = WebApplication.CreateBuilder(args); @@ -15,6 +17,8 @@ builder.Services.AddSignalR() .AddNamedAzureSignalR("signalr"); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.AddAzureCosmosClient(connectionName: "cosmos-db"); builder.AddKeyedAzureTableClient("clustering"); @@ -59,10 +63,6 @@ } -//builder.Services.ExtendOptions(); -//builder.Services.ExtendServices(); -//builder.Services.RegisterSemanticKernelNativeFunctions(); - builder.UseOrleans(siloBuilder => { siloBuilder.UseDashboard(x => x.HostSelf = true); diff --git a/samples/support-center/SupportCenter.ApiService/SemanticKernel/Extensions.cs b/samples/support-center/SupportCenter.ApiService/SemanticKernel/Extensions.cs deleted file mode 100644 index bbbdc2d..0000000 --- a/samples/support-center/SupportCenter.ApiService/SemanticKernel/Extensions.cs +++ /dev/null @@ -1,102 +0,0 @@ -using Azure.AI.OpenAI; -using Azure; -using Microsoft.Extensions.Options; -using Microsoft.SemanticKernel.Memory; -using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.Connectors.Qdrant; -using Microsoft.SemanticKernel.Connectors.AzureAISearch; -using SupportCenter.ApiService.Extensions; -using SupportCenter.ApiService.AgentsConfigurationFactory; -using SupportCenter.ApiService.Options; -using OpenAI; - -namespace SupportCenter.ApiService.SemanticKernel -{ - public static class Extensions - { - public static ISemanticTextMemory CreateMemory(IServiceProvider provider, string agent) - { - OpenAIOptions openAiConfig = provider.GetService>()?.Value ?? new OpenAIOptions(); - openAiConfig.ValidateRequiredProperties(); - - var loggerFactory = LoggerFactory.Create(builder => - { - builder - .SetMinimumLevel(LogLevel.Debug) - .AddConsole() - .AddDebug(); - }); - - if (agent == "Invoice") - { - AISearchOptions aiSearchConfig = provider.GetService>()?.Value ?? new AISearchOptions(); - aiSearchConfig.ValidateRequiredProperties(); - - var memoryBuilder = new MemoryBuilder(); - return memoryBuilder.WithLoggerFactory(loggerFactory) - .WithMemoryStore(new AzureAISearchMemoryStore(aiSearchConfig.SearchEndpoint, aiSearchConfig.SearchKey)) - //.WithAzureOpenAITextEmbeddingGeneration(aiSearchConfig.SearchEmbeddingDeploymentOrModelId, aiSearchConfig.SearchEmbeddingEndpoint, aiSearchConfig.SearchEmbeddingApiKey) - .Build(); - } - else - { - QdrantOptions qdrantConfig = provider.GetService>()?.Value ?? new QdrantOptions(); - qdrantConfig.ValidateRequiredProperties(); - - return new MemoryBuilder().WithLoggerFactory(loggerFactory) - .WithQdrantMemoryStore(qdrantConfig.Endpoint, qdrantConfig.VectorSize) - //.WithAzureOpenAITextEmbeddingGeneration(openAiConfig.EmbeddingsDeploymentOrModelId, openAiConfig.EmbeddingsEndpoint, openAiConfig.EmbeddingsApiKey) - .Build(); - } - } - - public static Kernel CreateKernel(IServiceProvider provider, string agent) - { - var client = provider.GetService(); - - var agentConfiguration = AgentConfiguration.GetAgentConfiguration(agent); - //agentConfiguration.ConfigureOpenAI(openAiConfig); - - //var clientOptions = new AzureOpenAIClientOptions(); - //clientOptions.Retry.NetworkTimeout = TimeSpan.FromMinutes(5); - var builder = Kernel.CreateBuilder(); - //builder.AddAzureOpenAIChatCompletion("", client); - //builder.AddAzureOpenAIChatCompletion(client); - //builder.Services.AddLogging(c => c.AddConsole().AddDebug().SetMinimumLevel(LogLevel.Debug)); - - //// Chat - //if (openAiConfig.ChatEndpoint.Contains(".azure", StringComparison.OrdinalIgnoreCase)) - //{ - // builder.Services.AddAzureOpenAIChatCompletion(openAiConfig.ChatDeploymentOrModelId, openAIClient); - //} - //else - //{ - // builder.Services.AddOpenAIChatCompletion(openAiConfig.ChatDeploymentOrModelId, openAIClient); - //} - //// Embeddings - //openAIClient = new AzureOpenAIClient(new Uri(openAiConfig.EmbeddingsEndpoint), new AzureKeyCredential(openAiConfig.EmbeddingsApiKey), clientOptions); - //if (openAiConfig.EmbeddingsEndpoint.Contains(".azure", StringComparison.OrdinalIgnoreCase)) - //{ - // builder.Services.AddAzureOpenAITextEmbeddingGeneration(openAiConfig.EmbeddingsDeploymentOrModelId, openAIClient); - //} - //else - //{ - // builder.Services.AddOpenAITextEmbeddingGeneration(openAiConfig.EmbeddingsDeploymentOrModelId, openAIClient); - //} - - //builder.Services.ConfigureHttpClientDefaults(c => - //{ - // c.AddStandardResilienceHandler().Configure(o => - // { - // o.Retry.MaxRetryAttempts = 5; - // o.Retry.BackoffType = Polly.DelayBackoffType.Exponential; - // }); - //}); - - var kernel = builder.Build(); - agentConfiguration.ConfigureKernel(kernel, provider); - - return kernel; - } - } -} diff --git a/samples/support-center/SupportCenter.ApiService/SignalRHub/SupportCenterHub.cs b/samples/support-center/SupportCenter.ApiService/SignalRHub/SupportCenterHub.cs index 55ce4c3..937de6f 100644 --- a/samples/support-center/SupportCenter.ApiService/SignalRHub/SupportCenterHub.cs +++ b/samples/support-center/SupportCenter.ApiService/SignalRHub/SupportCenterHub.cs @@ -5,7 +5,7 @@ using Orleans.Runtime; using Orleans; using SupportCenter.ApiService.Events; -using SupportCenter.ApiService.Options; +using SupportCenter.ApiService; public class SupportCenterHub : Hub {