semantic-kernel
semantic-kernel copied to clipboard
Function config extensibility
Motivation and Context
NOTE: This PR contains breaking changes, that are applied to SK C# version only, Python version is not included.
Currently, config.json is coupled to completion settings only, which are specific to OpenAI parameters (e.g. temperature, presence_penalty, frequency_penalty etc).
In order to allow AI extensibility in the future, we need to update config.json schema to allow flexible settings format for different AI models.
We also need to be able to specify recommended services for function, so Semantic Kernel will be able to automatically use one of the recommended services in case if it's registered.
New config.json proposed schema:
{
"description": "Generate a funny joke",
"input": {
"parameters": [
{
"name": "input",
"description": "Joke subject",
"defaultValue": ""
}
]
},
"default_settings": {
"max_tokens": 256,
"temperature": 0.9
},
"services": [
{
"model_id": "text-davinci-003",
"order": 1,
"settings": {
"max_tokens": 1000,
"temperature": 0.9,
"top_p": 0.0,
"presence_penalty": 0.0,
"frequency_penalty": 0.0,
"stop_sequences": [
"\n"
]
}
},
{
"model_id": "gpt-3.5-turbo",
"order": 2,
"settings": {
"system_message": "You are assistant to generate funny jokes",
"max_tokens": 1000,
"temperature": 0.9
}
},
{
"model_id": "dalle",
"order": 3,
"settings": {
"n": 1,
"size": "1024x1024"
}
},
{
"model_id": "gpt2",
"order": 4
}
]
}
Schema description:
- description: as it was previously, describes purpose of the function.
- input: as it was previously, contains information about input parameters.
- default_settings: contains default settings for AI model. Will be used when there is no matching recommended AI service, which is registered in kernel.
-
services (optional): contains list of recommended AI services to use when running a function. Contains objects with following properties:
- model_id: model identifier as described by AI provider, e.g. text-davinci-003.
- order: service priority order. Kernel will choose recommended service which is registered and has highest priority order. Used to avoid coupling on how (in what order) services are located in JSON file.
- settings: dynamic object, which can contain any properties, specific to AI model. Will be defined in C# using System.Text.Json.Nodes.JsonObject.
Description
- Replaced
CompleteRequestSettingsin AI service interfaces toJsonObject. - Updated
Kernelto use recommended service ordefault_settingsby default. - Added
SKFunctionConfigTests.cstests which show usage of new config.json. - Updated all config.json files in samples to follow new format.
Contribution Checklist
- [x] The code builds clean without any errors or warnings
- [x] The PR follows SK Contribution Guidelines (https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the .NET coding conventions (https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) verified with
dotnet format - [x] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone :smile: