microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
21.79k stars 3.24k forks source link

.Net: Simple ASP.NET Core WebAPI example for Semantic Kernel? #4960

Closed bbence84 closed 4 months ago

bbence84 commented 8 months ago

Is there maybe a simple example how I could expose a working SK app via ASP.NET Core WebAPI / using WebApplication? I can create a simple endpoint that works with the regular Azure OpenAI APIs, but I am unsure what is the best practice for exposing an SK Kernel, which is supposed to be stateful. I know about the chat-copilot github repository, but that seems way too excessive for a simple prototype. :) Ideally the Chat endpoint should support streaming responses, which I could consume on the client side. And somehow (maybe using kernel-memory?) it should support user sessions. Thanks!

matthewbolanos commented 8 months ago

Adding @glahaye who's working on a sample like this as we speak :)

Xyloto91 commented 8 months ago

@glahaye when we can expect sample code visible on github?

glahaye commented 8 months ago

@Xyloto There's a PR for an example app: #4940

It isn't a WebAPI example per se but it should be a good starting point.

bbence84 commented 7 months ago

Any update on this? I would ideally like to have a simple WebAPI endpoint which could expose my existing SK POC, even if does not support streaming. I am unsure what the best approach would be: should the conversation history be kept on client side (as seen in many OpenAI chat examples), or should be kept on the server side, e.g. maybe using KernelMemory?

I would really appreciate some help with this to get me started. :)

glahaye commented 6 months ago

@bbence84 You can take a look at https://github.com/microsoft/semantic-kernel/tree/main/dotnet/samples/HomeAutomation and its associated blog post: https://devblogs.microsoft.com/semantic-kernel/using-semantic-kernel-with-dependency-injection/

Just use WebApplication.CreateBuilder() instead of HostApplicationBuilder.CreateApplicationBuilder().

Then you can inject transient or session instances of Kernel into your controller.

I hope this helps.