Skip to content

Commit

Permalink
Merge pull request #117 from Azure-Samples/gk/generative-usecases
Browse files Browse the repository at this point in the history
default to volatile memory and update native connector
  • Loading branch information
thegovind committed Jul 13, 2023
2 parents b61fdd6 + 7a2a006 commit 97ba5cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
4 changes: 3 additions & 1 deletion dotnet/recommendation-service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 17 additions & 13 deletions dotnet/recommendation-service/plugins/UserProfilePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System.ComponentModel;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.SkillDefinition;

Expand Down Expand Up @@ -32,18 +33,18 @@ public class UserProfilePlugin
/// SKContext[UserProfilePlugin.UserId] = "000"
/// </example>
/// <param name="context">Contains the context variables.</param>
[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;
}
Expand All @@ -55,20 +56,23 @@ public string GetUserAge(SKContext context)
// invoke a service to get the age of the user, given the userId
return age.ToString();
}

/// <summary>
/// Lookup User's annual income given UserId.
/// </summary>
/// <example>
/// SKContext[UserProfilePlugin.UserId] = "000"
/// </example>
/// <param name="context">Contains the context variables.</param>
[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();
Expand Down

0 comments on commit 97ba5cb

Please sign in to comment.