mirror of
https://github.com/jcreek/WhoAtX.git
synced 2026-07-12 18:53:44 +00:00
Merge pull request #16 from jcreek/5-add-semantic-kernel-skill-to-find-a-person-for-a-given-query
feat(#5): Add ask controller and WhoCanHelpWithX endpoint
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.002.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WhoAtX", "WhoAtX\WhoAtX.csproj", "{45C8EE64-AE4C-4B6A-ABD5-2D0C1517A42D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{45C8EE64-AE4C-4B6A-ABD5-2D0C1517A42D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{45C8EE64-AE4C-4B6A-ABD5-2D0C1517A42D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{45C8EE64-AE4C-4B6A-ABD5-2D0C1517A42D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{45C8EE64-AE4C-4B6A-ABD5-2D0C1517A42D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {BAE8E8E9-EE55-4544-954C-638B3A2E62C3}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,58 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.SemanticKernel;
|
||||
|
||||
namespace WhoAtX.Controllers;
|
||||
|
||||
public class AskController : Controller
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
private readonly IKernel _kernel;
|
||||
private readonly ILogger<AskController> _logger;
|
||||
|
||||
public AskController(ILogger<AskController> logger, IConfiguration config)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
|
||||
// N.B. Swap this if not using Using Azure
|
||||
_kernel = new KernelBuilder()
|
||||
.WithAzureChatCompletionService(
|
||||
_config["OpenAi:DeploymentName"] ?? throw new Exception("DeploymentName is null"),
|
||||
_config["OpenAi:Endpoint"] ?? throw new Exception("Endpoint is null"),
|
||||
_config["OpenAi:ApiKey"] ?? throw new Exception("ApiKey is null")
|
||||
)
|
||||
// .WithOpenAIChatCompletionService()
|
||||
.Build();
|
||||
}
|
||||
|
||||
public async Task<JsonResult> WhoCanHelpWithX(string queryText)
|
||||
{
|
||||
// Define the semantic function
|
||||
const string promptTemplate = """
|
||||
Who at my organisation can help me with my query?
|
||||
|
||||
===== QUERY =====
|
||||
{{$input}}
|
||||
===== END QUERY =====
|
||||
|
||||
Please ensure that you respond in a professional and courteous manner, making full use of the information about relevant employees. This includes:
|
||||
- Name
|
||||
- Team
|
||||
- Link to their user profile (using the Id)
|
||||
- Areas of knowledge
|
||||
- Projects
|
||||
|
||||
If the query is not about finding someone within my organisation to then please only respond to tell me that you can only help with queries about finding someone within my organisation.
|
||||
|
||||
Engage.
|
||||
""";
|
||||
var whoCanHelpWithXFunction = _kernel.CreateSemanticFunction(promptTemplate);
|
||||
|
||||
// Perform the ask
|
||||
var result = (await whoCanHelpWithXFunction.InvokeAsync(queryText, _kernel))
|
||||
.GetValue<string>();
|
||||
|
||||
// TODO(#15) - add the NL2SQL plugin to retrieve data from the SQL database, enabling this query to access the relevant data. It must be run using a read-only user to ensure that it cannot change data.
|
||||
return Json(result);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,8 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.11" />
|
||||
<PackageReference Include="Microsoft.SemanticKernel" Version="0.24.230912.2-preview" />
|
||||
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.0-beta1" />
|
||||
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Memory" Version="1.0.0-beta1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -8,5 +8,10 @@
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=UserDatabase.sqlite"
|
||||
},
|
||||
"OpenAi": {
|
||||
"ApiKey": "",
|
||||
"DeploymentName": "",
|
||||
"Endpoint": ""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user