mirror of
https://github.com/microsoft/autogen.git
synced 2026-04-20 03:02:16 -04:00
switch to lib skills
This commit is contained in:
@@ -6,6 +6,7 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
|
||||
using Microsoft.SemanticKernel;
|
||||
using Microsoft.SemanticKernel.Orchestration;
|
||||
using Models;
|
||||
using skills;
|
||||
|
||||
public class ExecuteFunctionEndpoint
|
||||
{
|
||||
@@ -31,36 +32,14 @@ public class ExecuteFunctionEndpoint
|
||||
HttpRequestData requestData,
|
||||
FunctionContext executionContext, string skillName, string functionName)
|
||||
{
|
||||
#pragma warning disable CA1062
|
||||
try
|
||||
{
|
||||
var functionRequest = await JsonSerializer.DeserializeAsync<ExecuteFunctionRequest>(requestData.Body, s_jsonOptions).ConfigureAwait(false);
|
||||
#pragma warning disable CA1062
|
||||
// note: using skills from the repo
|
||||
var skillsDirectory = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "skills");
|
||||
|
||||
var skillDirectory = Path.Combine(skillsDirectory, skillName);
|
||||
if (!System.IO.Directory.Exists(skillDirectory))
|
||||
{
|
||||
return await CreateResponseAsync(requestData, HttpStatusCode.NotFound, new ErrorResponse() { Message = $"Unable to find {skillName}" }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
//var pmReadme = _kernel.CreateSemanticFunction(skills.PM.Readme.PromptTemplate,);
|
||||
|
||||
|
||||
var skill = this._kernel.ImportSemanticSkillFromDirectory(skillsDirectory, skillName);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!skill.ContainsKey(functionName))
|
||||
{
|
||||
return await CreateResponseAsync(requestData, HttpStatusCode.NotFound, new ErrorResponse() { Message = $"Unable to find {skillName}.{functionName}" }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var function = skill[functionName];
|
||||
var skillConfig = SemanticFunctionConfig.ForSkillAndFunction(skillName, functionName);
|
||||
var function = _kernel.CreateSemanticFunction(skillConfig.PromptTemplate, skillConfig.Name, skillConfig.SkillName,
|
||||
skillConfig.Description, skillConfig.MaxTokens, skillConfig.Temperature,
|
||||
skillConfig.TopP, skillConfig.PPenalty, skillConfig.FPenalty);
|
||||
|
||||
var context = new ContextVariables();
|
||||
foreach (var v in functionRequest.Variables)
|
||||
@@ -80,8 +59,6 @@ public class ExecuteFunctionEndpoint
|
||||
|
||||
return await CreateResponseAsync(requestData, HttpStatusCode.BadRequest, new ErrorResponse() { Message = $"Invalid request body." }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static async Task<HttpResponseData> CreateResponseAsync(HttpRequestData requestData, HttpStatusCode statusCode, object responseBody)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
namespace skills;
|
||||
|
||||
public class SemanticFunctionConfig
|
||||
{
|
||||
public string PromptTemplate { get; set; }
|
||||
@@ -10,4 +11,13 @@ public class SemanticFunctionConfig
|
||||
public double TopP { get; set; }
|
||||
public double PPenalty { get; set; }
|
||||
public double FPenalty { get; set; }
|
||||
private static SemanticFunctionConfig ForSkillAndFunction(string skillName, string functionName) =>
|
||||
(skillName, functionName) switch
|
||||
{
|
||||
(nameof(PM), nameof(PM.BootstrapProject)) => PM.BootstrapProject,
|
||||
(nameof(PM), nameof(PM.Readme)) => PM.Readme,
|
||||
(nameof(DevLead), nameof(DevLead.Plan)) => DevLead.Plan,
|
||||
(nameof(Developer), nameof(Developer.Implement)) => Developer.Implement,
|
||||
_ => throw new ArgumentException($"Unable to find {skillName}.{functionName}")
|
||||
};
|
||||
}
|
||||
@@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>skills</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SemanticKernel" Version="0.14.547.1-preview" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user