From 7a2a006e7757d24aac90abf84cbbf6343d78156d Mon Sep 17 00:00:00 2001 From: Govind Kamtamneni Date: Thu, 13 Jul 2023 19:31:01 -0400 Subject: [PATCH] default to volatile memory and update native connector --- dotnet/recommendation-service/Program.cs | 4 ++- .../plugins/UserProfilePlugin.cs | 30 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/dotnet/recommendation-service/Program.cs b/dotnet/recommendation-service/Program.cs index 6f8fe3ac..b4bc646f 100644 --- a/dotnet/recommendation-service/Program.cs +++ b/dotnet/recommendation-service/Program.cs @@ -28,7 +28,9 @@ { // initialize the kernel var kernelSettings = KernelSettings.LoadSettings(); - var memoryStore = new QdrantMemoryStore(Env.Var("QDRANT_ENDPOINT"), 1536, ConsoleLogger.Log); + // Uncomment below line to use Qdrant + // var memoryStore = new QdrantMemoryStore(Env.Var("QDRANT_ENDPOINT"), 1536, ConsoleLogger.Log); + var memoryStore = new VolatileMemoryStore(); IKernel kernel = new KernelBuilder() .WithLogger(NullLogger.Instance) diff --git a/dotnet/recommendation-service/plugins/UserProfilePlugin.cs b/dotnet/recommendation-service/plugins/UserProfilePlugin.cs index fd0da695..2645ca19 100644 --- a/dotnet/recommendation-service/plugins/UserProfilePlugin.cs +++ b/dotnet/recommendation-service/plugins/UserProfilePlugin.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ComponentModel; using Microsoft.SemanticKernel.Orchestration; using Microsoft.SemanticKernel.SkillDefinition; @@ -32,18 +33,18 @@ public class UserProfilePlugin /// SKContext[UserProfilePlugin.UserId] = "000" /// /// Contains the context variables. - [SKFunction("Given a userId, get user age")] - [SKFunctionName("GetUserAge")] - [SKFunctionContextParameter(Name = UserId, Description = "UserId", DefaultValue = DefaultUserId)] - public string GetUserAge(SKContext context) + [SKFunction, SKName("GetUserAge"), Description("Given a userId, get user age")] + public string GetUserAge( + [Description("Unique identifier of a user")] string userId, + SKContext context) { - var userId = context.Variables.ContainsKey(UserId) ? context[UserId] : DefaultUserId; + // userId = context.Variables.ContainsKey(UserId) ? context[UserId] : DefaultUserId; + userId = string.IsNullOrEmpty(userId) ? DefaultUserId : userId; context.Log.LogDebug("Returning hard coded age for {0}", userId); - int parsedUserId; int age; - if (int.TryParse(userId, out parsedUserId)) + if (int.TryParse(userId, out var parsedUserId)) { age = parsedUserId > 100 ? (parsedUserId % Normalize) : parsedUserId; } @@ -55,7 +56,7 @@ public string GetUserAge(SKContext context) // invoke a service to get the age of the user, given the userId return age.ToString(); } - + /// /// Lookup User's annual income given UserId. /// @@ -63,12 +64,15 @@ public string GetUserAge(SKContext context) /// SKContext[UserProfilePlugin.UserId] = "000" /// /// Contains the context variables. - [SKFunction("Given a userId, get user annual household income")] - [SKFunctionName("GetAnnualHouseholdIncome")] - [SKFunctionContextParameter(Name = UserId, Description = "UserId", DefaultValue = DefaultUserId)] - public string GetAnnualHouseholdIncome(SKContext context) + [SKFunction, + SKName("GetAnnualHouseholdIncome"), + Description("Given a userId, get user annual household income")] + public string GetAnnualHouseholdIncome( + [Description("Unique identifier of a user")] string userId, + SKContext context) { - var userId = context.Variables.ContainsKey(UserId) ? context[UserId] : DefaultUserId; + // userId = context.Variables.ContainsKey(UserId) ? context[UserId] : DefaultUserId; + userId = string.IsNullOrEmpty(userId) ? DefaultUserId : userId; context.Log.LogDebug("Returning userId * randomMultiplier for {0}", userId); var random = new Random();