Replies: 3 comments 5 replies
-
Just to add more. I just noticed that |
Beta Was this translation helpful? Give feedback.
-
Hi @rosieks
Thanks again for taking the time to provide your feedback, I'll share this with the team. |
Beta Was this translation helpful? Give feedback.
-
@rosieks Regarding Dependency Injection, I've already implemented several web applications with Semantic Kernel and my DI setup looks like this all the time: var builder = WebApplication.CreateBuilder(args);
// Add Semantic Kernel
builder.Services.AddKernel();
builder.Services.AddOpenAIChatCompletion(openAIOptions.ChatModelId, openAIOptions.ApiKey); When I want to include some plugins, I just import them in place where I want them to be used, for example in some service, where I inject a Kernel: this._kernel.ImportPluginFromType<TimePlugin>();
this._kernel.ImportPluginFromType<WeatherPlugin>(); Taking into account, that my Kernel is transient, it's always injected to my service without Plugins, which allows me to share with AI only those plugins I want to use in specific place of my application, but not all of them. Because I may have plugins related to different domain entities in my app, so I definitely want to separate them. I would avoid registering a lot of plugins and Kernel as singletons and use them in all places of my app without any isolation. In SK codebase, there is no simple way to register Kernel and Plugin collection as singletons, because I'm not sure it's the best practice, and as far as I understand, your complaint about DI is related to singleton and scoped lifecycles. In Kernel, you can mutate Plugin Collection. If Plugin Collection will be a singleton, you may end up with two different Kernel instances that will mutate the same Plugin Collection, which may lead to unexpected behavior. That's why extension method It would be really helpful if you could share some information about your use case to better understand the purpose of registering Kernel and Plugin collection as scoped/singleton, so we can prioritize it. If you are interested in sharing some state and scoped/singleton lifecycle works better for you, you can still achieve that with more complex registration logic, but so far it doesn't look like a common scenario, and current extension methods cover most of the cases. If it's not true, we will definitely add more helpers to simplify DI if needed. Regarding a responsibility of Kernel, I think it's possible to work without it, but if you need Plugins, Chat/Text completion service, Prompt Template Engines, Middleware, Telemetry etc, you can do that without Kernel, but you will need to pass these things around your application as a bundle and manage it on your side. I think Kernel works like a container, which you can re-use multiple times in your app, so in business logic you don't need to operate with these multiple components and mix this logic, you just need one Kernel. So, it works like DI container plus entrypoint to AI at the same time. Currently, we mostly focus on I hope that makes sense and thank you for feedback! |
Beta Was this translation helpful? Give feedback.
-
I'm following Semantic Kernel for about half year if not longer I have impression that design of the framework is messy and hard to understand.
Kernel
. There isKernel
object but what's the responsibility of that?1.1. It has reference
IServiceProvider
but what for? For that reasons we haveIServiceProvider
and we can inject specific AI service directly to our class without having reference toKernel
.1.2. It stores plugins. But do they work with all AI Services or only with
IChatCompletion
and only for specific implementations.1.3. If I register plugins in
Kernel
, then I will call function to getIChatCompletion
service it's still not aware of those plugins. I have to pass Kernel back as parameter. The same if I create function from prompt and want to invoke it. Despite it was created by this Kernel.1.4. I can use
Kernel
to create function from prompt. But not, wait a minute. It only takes it to get logger. If I want invoke that function I have to pass Kernel again as parameter.1.5. In general
Kernel
looks like some kind of god class that mix multiple responsibilities (services factory, filters pipeline, plugins register class that provides reference to logger) and maybe should be splited.IChatCompletion
looks like unnecessary abstraction because when we want to invoke AI we have to provide specific (or at least that what we see in most samples)PromptExecutionSettings
with model specific configuration.I don't know if that's only mine impression or there are others who think the same.
Beta Was this translation helpful? Give feedback.
All reactions