Skip to content

Lesson 4: Describe all plugins in Semantic Kernel chatbotΒΆ

In this lesson we will add functionality to list all plugins and plugin parameters that are loaded in the application's Semantic Kernel instance.

  1. Ensure all pre-requisites are met and installed.

  2. Switch to Lesson 5 directory:

    cd ../Lesson4
    
  3. Start by copying appsettings.json from Lesson 1:

    cp ../Lesson1/appsettings.json .
    
  4. Run program to validate the code is functional:

    dotnet run
    
  5. Locate TODO: Step 1 - Add import for ModelExtensionMethods in Program.cs and add the following import:

    using Core.Utilities.Extensions;
    
  6. Next locate TODO: Step 2 - add call to print all plugins and functions in Program.cs and add the following lines to print out kernel plugins info:

    var functions = kernel.Plugins.GetFunctionsMetadata();
    Console.WriteLine(functions.ToPrintableString());
    
  7. Next locate TODO: Step 3 - Comment out all code after "Execute program" comment and comment all lines of code after the //Execute program line.

    // TODO: Step 3 - Comment out all code after "Execute program" comment
    // Execute program.
    /*
    const string terminationPhrase = "quit";
    ...
    while (userInput != terminationPhrase);
    */
    
  8. Re-run the program and you should see an output similar to this:

    **********************************************
    ****** Registered plugins and functions ******
    **********************************************
    
    Plugin: GetCurrentUtcTime
    GetCurrentUtcTime: Retrieves the current time in UTC.
    
    Plugin: GetStockPrice
    GetStockPrice: Gets stock price
        Params:
        - symbol:
            default: ''
    
    Plugin: GetStockPriceForDate
    GetStockPriceForDate: Gets stock price for a given date
        Params:
        - symbol:
            default: ''
        - date:
            default: ''
    
  9. Review the Core.Utilities.Extensions.ModelExtensionMethods class in the CoreUtilities project to understand how the plugins are traversed to print out plugins and corresponding plugin parameters information.