Explore practical examples of using SemanticPluginForge
in different scenarios. Each sample includes comprehensive documentation, setup instructions, and focuses on specific framework concepts.
Focus: Advanced parameter handling including suppression, default values, and context-aware metadata
Demonstrates how to use intelligent default values and parameter handling in plugin metadata. Shows how custom metadata providers can provide context-aware defaults and guide LLM behavior for improved user experience.
Key Concepts:
What You’ll Learn:
Sample Code Preview:
public class WeatherMetadataProvider : IPluginMetadataProvider
{
public FunctionMetadata? GetFunctionMetadata(KernelPlugin plugin, KernelFunctionMetadata metadata)
{
if (plugin.Name == "WeatherPlugin" && metadata.Name == "GetWeather")
{
return new FunctionMetadata(metadata.Name)
{
Description = "Gets weather information. Location is automatically detected from user context.",
Parameters = new List<ParameterMetadata>
{
new ParameterMetadata("location")
{
Suppress = true,
DefaultValue = "user_current_location",
Description = "Location automatically resolved from user context"
}
}
};
}
return null;
}
}
Focus: CLR type registration and metadata enhancement
Shows how to convert existing .NET classes into Semantic Kernel plugins using both type-based and object-based registration approaches. Demonstrates integration of existing codebases with AI applications.
Key Concepts:
What You’ll Learn:
Sample Code Preview:
public class ShortDate
{
public string ToShortDateString()
{
return DateTime.Now.ToShortDateString();
}
}
public class DateMetadataProvider : IPluginMetadataProvider
{
public FunctionMetadata? GetFunctionMetadata(KernelPlugin plugin, KernelFunctionMetadata metadata)
{
if (plugin.Name == "ShortDatePlugin" && metadata.Name == "ToShortDateString")
{
return new FunctionMetadata(metadata.Name)
{
Description = "Returns the current date in short format (MM/dd/yyyy)."
};
}
return null;
}
}
// Registration
kernelBuilder.Plugins.AddFromClrTypeWithMetadata<ShortDate>("ShortDatePlugin");
Focus: Multiple plugin instances with different metadata configurations
Comprehensive example showing how to create multiple instances of the same plugin class with different metadata configurations for various data sources. Uses mocked data for learning without external dependencies.
Key Concepts:
What You’ll Learn:
Sample Code Preview:
public class SearchPlugin
{
private readonly string _dataSource;
public SearchPlugin(string dataSource)
{
_dataSource = dataSource;
}
public async Task<string> Search(string query)
{
// Implementation varies based on data source
return await SearchInDataSource(query, _dataSource);
}
}
public class SearchMetadataProvider : IPluginMetadataProvider
{
public FunctionMetadata? GetFunctionMetadata(KernelPlugin plugin, KernelFunctionMetadata metadata)
{
// Different descriptions based on plugin instance
return plugin.Name switch
{
"ProductSearchPlugin" => new FunctionMetadata(metadata.Name)
{
Description = "Searches product catalog for items matching the query"
},
"DocumentSearchPlugin" => new FunctionMetadata(metadata.Name)
{
Description = "Searches document repository for content matching the query"
},
_ => null
};
}
}
All samples require Azure OpenAI configuration. Navigate to any sample folder and configure your secrets:
dotnet user-secrets init
dotnet user-secrets set "AzureOpenAI:ChatDeploymentName" "YOUR_DEPLOYMENT_NAME"
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://YOUR_ENDPOINT.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:ApiKey" "YOUR_API_KEY"
Then run the sample:
dotnet run
Each sample expects the following configuration:
Some samples may require additional configuration. Check the individual sample README files for specific requirements.
Recommended exploration order:
Each sample builds upon concepts from the previous ones while focusing on specific aspects of the framework.
Each sample includes:
Detailed documentation with:
Each sample includes suggestions for extending functionality:
Clear goals for each sample:
public class ExampleMetadataProvider : IPluginMetadataProvider
{
public PluginMetadata? GetPluginMetadata(KernelPlugin plugin)
{
// Plugin-level customizations
}
public FunctionMetadata? GetFunctionMetadata(KernelPlugin plugin, KernelFunctionMetadata metadata)
{
// Function-level customizations
}
}
var builder = Host.CreateApplicationBuilder(args);
// Register metadata providers
builder.Services.AddSingleton<IPluginMetadataProvider, ExampleMetadataProvider>();
// Configure Semantic Kernel
var kernelBuilder = builder.Services.AddKernel();
kernelBuilder.Plugins.AddFromTypeWithMetadata<ExamplePlugin>();
// Standard plugin with attributes
kernelBuilder.Plugins.AddFromTypeWithMetadata<StandardPlugin>();
// CLR type without attributes
kernelBuilder.Plugins.AddFromClrTypeWithMetadata<LegacyClass>("LegacyPlugin");
// Object instance
kernelBuilder.Plugins.AddFromClrObjectWithMetadata(instance, "InstancePlugin");
Before running the samples, ensure you have:
If you encounter issues with the samples:
We welcome contributions of new samples! Consider creating samples that demonstrate:
Navigate to the samples
folder to get started with these examples.