Duc Nguyen Thanh
Posted on November 15, 2024
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!
Posted on November 15, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.