Hello,
I'm Duke and I come back today to show you how to create a chatbox in .NET
by Bot Framework SDK
Microsoft created the robust Bot Framework SDK for.NET to make it easier to create conversational AI apps, or "bots," utilizing the.NET framework. This SDK makes it simple for developers to build bots that communicate with users through a variety of platforms, such as Facebook Messenger, Slack, and Microsoft Teams, increasing user engagement and automating a range of tasks.
Getting Started with Bot Framework SDK in .NET
1. Installation:
Install the Bot Framework SDK package via NuGet after creating a.NET project. For ASP.NET Core integration, Microsoft.Bot.Builder
and Microsoft.Bot.Builder.Integration.AspNet.Core
are the primary packages needed.
dotnet add package Microsoft.Bot.Builder
dotnet add package Microsoft.Bot.Builder.Integration.AspNet.Core
2. Basic Bot Structure:
The SDK has a simple structure for creating bots. Starting with a bot class that inherits from ActivityHandler, you can handle typical activities with methods like OnMessageActivityAsync
and OnMembersAddedAsync
.
3. Dialog Management:
Create dialogs to manage conversational flow. Use Waterfall dialogs for linear conversations and adaptive dialogs for more complex interactions, allowing for conditional responses based on user inputs.
4. Testing and Debugging: For local bot testing, Microsoft offers a desktop program called the Bot Framework Emulator. You may log actions, examine messages, and debug in real time with the emulator.
Use Case
For the "Open Source AI Challenge with pgai and Ollama" challenge, I made a chatbox to respond to inquiries concerning insurance or finance-related subjects.
Tools Used
To accomplish its responsive, high-performance AI capabilities, this project makes use of a number of potent tools and technologies:
- Database:PostgreSQL
server, provided by Timescale, serves as the foundational database for vector storage and querying.
- Programming Language: Built using.NET 8
for seamless and robust server-side execution.
- Model: UtilizedOllama’s nomic-embed-text
model to generate precise embeddings and support AI Bot’s semantic understanding.
- Embedding API: Ollama’sembedding API
enabled enhanced text matching and contextual understanding.
- Algorithm:Cosine Similarity
was implemented to measure and match query relevance.
- Cache: Optimized withMemory Cache
for faster responses and reduced computation time.
- AI Extension:pgvector
was instrumental in managing and querying vector data.
Demo: https://www.youtube.com/watch?v=MTUj1jAPEdk&feature=youtu.be
Repository: ngtduc693-AI-Hackathon-2024-pgai
Thank you for reading, and happy coding!
Top comments (10)
Let me know if you have any questions
Cool thanks! will try it out
Great one, do you have some resources on how to integrate with Facebook Messenger, Slack, and Microsoft Teams ? would like to read more on that!
I will guide in the next post about integrating other platforms like Facebook, the trick is to create Facebook App and webhook for it
Also is it easy to get it running locally?
@dsaga it's easy to run on locally, just run the server through the
dotnet run
commandCan you provide some guide on how to get it running?
Also how to connect it to an UI when pushing to production
You need to use the Azure AI Bot Service azure.microsoft.com/en-us/products... to integration with UI
Run it through by the dotnet run command or use an IDE such as Visual Studio or Rider