semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Integrate use of embeddings to determine related skills returned from FunctionView

Open lemillermicrosoft opened this issue 2 years ago • 5 comments

Motivation and Context

This pull request introduces several changes to the planner skill, which is a core skill that allows users to create and execute plans based on semantic queries. The motivation and context for these changes are as follows:

  • The changes improve the functionality and usability of the planner skill by adding several parameters and options to the planner skill functions, such as relevancy threshold, max functions, excluded functions, excluded skills, and included functions. These parameters allow users to customize the filtering and selection of registered functions based on their goals and preferences.
  • The changes enable the planner skill to filter the available functions based on a semantic query and the relevance score from the memory provider. This allows users to specify a natural language query that matches their intent and get the most relevant functions to execute. This feature enhances the planner skill's ability to generate and execute plans that are relevant, efficient, and customizable for different goals and scenarios.
  • The changes improve the user experience of the kernel syntax examples by adding more semantic skills and demonstrating how to use the planner skill to create a plan for a complex task.

These changes do not fix any open issues, but they are related to the ongoing development and improvement of the planner skill and the kernel framework. They also improve the test coverage and code quality of the planner skill, which is a key feature of the semantic kernel framework.

Description

  • Added a new class PlannerSkillConfig to encapsulate the configuration parameters for the PlannerSkill, such as the relevancy threshold, the max number of functions, and the lists of excluded and included functions and skills.
  • Added a new method GetPlannerSkillConfig to the SKContext class to retrieve the PlannerSkillConfig from the context variables.
  • Added a new method GetFunctionsManualAsync to the SKContext class to filter the registered functions based on the goal and the PlannerSkillConfig.
  • Refactored the CreatePlanAsync method of the PlannerSkill class to use the PlannerSkillConfig and the GetFunctionsManualAsync method.
  • Added some documentation and annotations to the PlannerSkill class and its methods.
  • Added a new class SKContextExtensionsTests to test the extension methods of SKContext that are used by the PlannerSkill.
  • Added a new property AzureOpenAIEmbeddings to the PlannerSkillConfig class, which allows specifying the deployment name for the Azure OpenAI embeddings service.
  • Added a new skill definition class TestSkillDefinition, which is used for testing the PlannerSkill with some mock functions.
  • Removed the '$' prefix from the input parameters in the function manual examples, to avoid confusion with variables.
  • Added a new extension method ToManualString to the FunctionView class, to simplify the generation of the function manual string.
  • Added a new extension method ToFunctionName to the FunctionView class, to get the full name of a function (skill name + function name).
  • Refactored the GetFunctionsManual method to be async and use the PlannerSkillConfig and the semantic query to filter the available functions.
  • Added a new constant for the memory collection name where the functions manual is stored.
  • Added a new example file for the kernel syntax project, demonstrating how to use the planning skill and import various semantic skills from different sources. The example also shows how to use the memory storage and the OpenAI embeddings service. The example file is named Example12_Planning.cs and is located in the samples/dotnet/kernel-syntax-examples folder.
  • Updated the kernel builder to use environment variables for the OpenAI embeddings service credentials.
  • Fixed a typo in the README.md file for the IntegrationTest project.

Contribution Checklist

  • [ ] The code builds clean without any errors or warnings
  • [ ] The PR follows SK Contribution Guidelines (https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
  • [ ] The code follows the .NET coding conventions (https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) verified with dotnet format
  • [ ] All unit tests pass, and I have added new tests where possible
  • [ ] I didn't break anyone :smile:

lemillermicrosoft avatar Mar 13 '23 21:03 lemillermicrosoft

<function.LanguageHelpers.TranslateTo translate_to_language=""Japanese"" setContextVariable=""TRANSLATED_TEXT"" />

this example is missing the input parameter. This may be why I am seeing the input sometimes not being populated in my own plans


Refers to: dotnet/src/SemanticKernel/CoreSkills/SemanticFunctionConstants.cs:46 in af02fd0. [](commit_id = af02fd02c83cda0b462be27f5b073af81dab4116, deletion_comment = False)

jofri-msft avatar Mar 16 '23 01:03 jofri-msft

<function.LanguageHelpers.TranslateTo translate_to_language=""Japanese"" setContextVariable=""TRANSLATED_TEXT"" />

Same with the summarize function. It is missing the input parameter value. I think the goal should include some specific text


In reply to: 1471121483


Refers to: dotnet/src/SemanticKernel/CoreSkills/SemanticFunctionConstants.cs:46 in af02fd0. [](commit_id = af02fd02c83cda0b462be27f5b073af81dab4116, deletion_comment = False)

jofri-msft avatar Mar 16 '23 01:03 jofri-msft

<function.WriterSkill.Summarize/>

the summary is missing a context variable to set to and pass to the translate to


Refers to: dotnet/src/SemanticKernel/CoreSkills/SemanticFunctionConstants.cs:45 in af02fd0. [](commit_id = af02fd02c83cda0b462be27f5b073af81dab4116, deletion_comment = False)

jofri-msft avatar Mar 16 '23 01:03 jofri-msft

<function.Magician.TranslateTo translate_to_language=""French"" setContextVariable=""TRANSLATED_SUMMARY""/>

same feedback about inputs param and context variable for these


Refers to: dotnet/src/SemanticKernel/CoreSkills/SemanticFunctionConstants.cs:75 in af02fd0. [](commit_id = af02fd02c83cda0b462be27f5b073af81dab4116, deletion_comment = False)

jofri-msft avatar Mar 16 '23 01:03 jofri-msft

<function.LanguageHelpers.TranslateTo translate_to_language=""Japanese"" setContextVariable=""TRANSLATED_TEXT"" />

this example is missing the input parameter. This may be why I am seeing the input sometimes not being populated in my own plans

Refers to: dotnet/src/SemanticKernel/CoreSkills/SemanticFunctionConstants.cs:46 in af02fd0. [](commit_id = af02fd0, deletion_comment = False)

This is by design right now. By default, the Result of a function is the Input of the next in the sequence.

  1. A function has an $input and an $output.
  2. The $output from each function is automatically passed as $input to the subsequent .
  3. $input does not need to be specified if it consumes the $output of the previous function.

lemillermicrosoft avatar Mar 16 '23 03:03 lemillermicrosoft