Inject context into functions #13082
Unanswered
Grégoire (verdie-g)
asked this question in
Q&A
Replies: 3 comments 2 replies
|
You could use the Something like this: var clonedKernel = kernel.Clone();
clonedKernel.Data["userId"] = "123";
// Use the clonedKernel, for example using IChatCompletionService
var completionService = clonedKernel.GetRequiredService<IChatCompletionService>();
...And in any plugin: [KernelFunction]
public Task DoSomethingAsync(Kernel kernel, ...)
{
var userId = kernel.Data["userId"]
...
} |
2 replies
|
I'm curious about how recommended this approach if kernel is registered as singleton |
0 replies
|
Other options that don't fight DI:
I would not put request-scoped data on a singleton kernel even with a lock. Clone or scope it. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'd like to be able to inject context, such as the user id associated to the current HTTP request. Is that possible with SK .NET?
I could try to do that by adding a userId parameter in my function and pass it in the prompt but that wouldn't be as reliable as fetching it from the context.
All reactions