Skip to content

Commit

Permalink
updated semantic kernel caused changes in POWER plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
s-o-w committed Mar 11, 2024
1 parent 04200ec commit 4e12616
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 52 deletions.
76 changes: 42 additions & 34 deletions webapi/POWERSkills/NativePlugins/ModelIdentifierPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Orchestration;
using System.ComponentModel;
using System.Threading.Tasks;

Expand All @@ -9,56 +8,65 @@ namespace POWEREngineers.Bucky.Skills.POWEREngPlugins;

public class ModelIdentifierPlugin
{
private IKernel _kernel;
private readonly Kernel _kernel;

public ModelIdentifierPlugin(IKernel kernel)
public ModelIdentifierPlugin(Kernel kernel)
{
this._kernel = kernel;
}

public ModelIdentifierPlugin() { }

[SKFunction, Description("Routes the request to the appropriate data retrieval function.")]
public async Task<string> RouteRequest(SKContext context)
[KernelFunction, Description("Routes the request to the appropriate data retrieval function.")]
public async Task<string> RouteRequest(KernelArguments context)
{
string data = string.Empty;
// check to see if we called this from AutoCAD and are using the AutoCAD Copilot
if (context.Variables.TryGetValue("POWERSkillTarget", out string? value))
if (context.TryGetValue("POWERSkillTarget", out object? value))
{
if (value == "LispForCAD")
if (value as string == "LispForCAD")
{
var cadSkill = this._kernel.Functions.GetFunction("CADPlugin", "LispForAutoCAD");
await cadSkill.InvokeAsync(context);
string toReturn = context.Variables["input"].Trim();
return $"CADCP data:{toReturn}";
var cadSkill = this._kernel.Plugins.GetFunction("CADPlugin", "LispForAutoCAD");
await cadSkill.InvokeAsync(this._kernel, context);
if (context.TryGetValue("input", out object? input))
{
var val = input as string;
return $"CADCP data:{val}";
}
return data;
}
return data;
}

// Save the original user request
string request = context.Variables["input"];
var request = context["input"] as string;

// Retrieve the intent from the user request
var targetModel = this._kernel.Functions.GetFunction("ModelIdentifierPlugin", "GetIntendedModel");
await targetModel.InvokeAsync(context);
string intent = context.Variables["input"].Trim();
string data = string.Empty;
// Call the appropriate function
switch (intent)
if (!string.IsNullOrEmpty(request))
{
case "PDQMS":
var qmsSkill = new POWERQMSSkill(this._kernel);
data = await qmsSkill.QueryQMSIndexAsync(request);
return $"PDQMS data:{data}";
case "POWERAUS":
var ausSkill = new POWERAUSSkill(this._kernel);
data = await ausSkill.QueryAUSModelAsync(request);
return $"POWERAUS data:{data}";
case "PDSUBKMP":
var kmpSkill = new POWERKMPSkill(this._kernel);
data = await kmpSkill.QueryKMPModelAsync(request);
return $"PDSUBKMP data:{data}";
case "UNKNOWN":
default:
return data;
// Retrieve the intent from the user request
var targetModel = this._kernel.Plugins.GetFunction("ModelIdentifierPlugin", "GetIntendedModel");
await targetModel.InvokeAsync(this._kernel, context);
string intent = request.Trim();
// Call the appropriate function
switch (intent)
{
case "PDQMS":
var qmsSkill = new POWERQMSSkill(this._kernel);
data = await qmsSkill.QueryQMSIndexAsync(request);
return $"PDQMS data:{data}";
case "POWERAUS":
var ausSkill = new POWERAUSSkill(this._kernel);
data = await ausSkill.QueryAUSModelAsync(request);
return $"POWERAUS data:{data}";
case "PDSUBKMP":
var kmpSkill = new POWERKMPSkill(this._kernel);
data = await kmpSkill.QueryKMPModelAsync(request);
return $"PDSUBKMP data:{data}";
case "UNKNOWN":
default:
break;
}
}
return data;
}
}
13 changes: 4 additions & 9 deletions webapi/POWERSkills/NativePlugins/POWERAUSSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace POWEREngineers.Bucky.Skills.POWEREngPlugins;

public class POWERAUSSkill
{
private IKernel _kernel;
public POWERAUSSkill(IKernel kernel)
private readonly Kernel _kernel;
public POWERAUSSkill(Kernel kernel)
{
this._kernel = kernel;
}
Expand All @@ -28,7 +28,7 @@ public POWERAUSSkill() { }
/// </summary>
/// <param name="query">Query to match.</param>
/// <param name="context">The SkContext.</param>
[SKFunction, Description("Call the POWER AUS Vector index to get information per the users context")]
[KernelFunction, Description("Call the POWER AUS Vector index to get information per the users context")]
//[SKParameter("query", "Query to match.")]
public async Task<string> QueryAUSIndexAsync(string query)
{
Expand All @@ -55,11 +55,6 @@ public async Task<string> QueryAUSIndexAsync(string query)
//vector = vector,
Size = 10,
QueryType = SearchQueryType.Semantic,
QueryLanguage = QueryLanguage.EnUs,
SemanticConfigurationName = "aus-semantic-config",
QueryCaption = QueryCaptionType.Extractive,
QueryAnswer = QueryAnswerType.Extractive,
QueryCaptionHighlightEnabled = true,
Select = { "id", "Description", "Text", "ExternalSourceName" },
};

Expand All @@ -85,7 +80,7 @@ public async Task<string> QueryAUSIndexAsync(string query)
/// </summary>
/// <param name="query">Query to match.</param>
/// <param name="context">The SkContext.</param>
[SKFunction, Description("Call the POWER AUS ML Model to get information per the users context")]
[KernelFunction, Description("Call the POWER AUS ML Model to get information per the users context")]
//[SKParameter("query", "Query to match.")]
public async Task<string> QueryAUSModelAsync(string query)
{
Expand Down
6 changes: 3 additions & 3 deletions webapi/POWERSkills/NativePlugins/POWERCADCopilotSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace POWEREngineers.Bucky.Skills.POWEREngPlugins;

public class CADCopilotSkill
{
private IKernel _kernel;
public CADCopilotSkill(IKernel kernel)
private Kernel _kernel;
public CADCopilotSkill(Kernel kernel)
{
this._kernel = kernel;
}
Expand All @@ -19,7 +19,7 @@ public CADCopilotSkill() { }
/// </summary>
/// <param name="query">Query to match.</param>
/// <param name="context">The SkContext.</param>
[SKFunction, Description("Use GPT-4 to generate Lisp code to help drafters create content in drawings")]
[KernelFunction, Description("Use GPT-4 to generate Lisp code to help drafters create content in drawings")]
//[SKParameter("query", "Query to match.")]
public async Task<string> GenerateResponse(string query)
{
Expand Down
6 changes: 3 additions & 3 deletions webapi/POWERSkills/NativePlugins/POWERKMPSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace POWEREngineers.Bucky.Skills.POWEREngPlugins;

public class POWERKMPSkill
{
private IKernel _kernel;
public POWERKMPSkill(IKernel kernel)
private Kernel _kernel;
public POWERKMPSkill(Kernel kernel)
{
this._kernel = kernel;
}
Expand All @@ -22,7 +22,7 @@ public POWERKMPSkill() { }
/// </summary>
/// <param name="query">Query to match.</param>
/// <param name="context">The SkContext.</param>
[SKFunction, Description("Call the POWER Substation KMP ML Model to get information per the users context")]
[KernelFunction, Description("Call the POWER Substation KMP ML Model to get information per the users context")]
//[SKParameter("query", "Query to match.")]
public async Task<string> QueryKMPModelAsync(string query)
{
Expand Down
6 changes: 3 additions & 3 deletions webapi/POWERSkills/NativePlugins/POWERQMSSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace POWEREngineers.Bucky.Skills.POWEREngPlugins;

public class POWERQMSSkill
{
private IKernel _kernel;
public POWERQMSSkill(IKernel kernel)
private Kernel _kernel;
public POWERQMSSkill(Kernel kernel)
{
this._kernel = kernel;
}
Expand All @@ -22,7 +22,7 @@ public POWERQMSSkill() { }
/// </summary>
/// <param name="query">Query to match.</param>
/// <param name="context">The SkContext.</param>
[SKFunction, Description("Call the POWER QMS Data prompt-flow endpoint to get information")]
[KernelFunction, Description("Call the POWER QMS Data prompt-flow endpoint to get information")]
//[SKParameter("query", "Query to match.")]
public async Task<string> QueryQMSIndexAsync(string query)
{
Expand Down

0 comments on commit 4e12616

Please sign in to comment.