Welcome to the Adding AI to Your Existing .NET Apps Workshop. This repository contains a set of .NET projects to demostrate how to add AI to a common .NET scenario: Winform as front end app, and an WebAPI as backend.
The following image shows the WinForm Chat App interacting with an GPT-4o model in Azure OpenAI, and metrics traced using Aspire Dashboard.
These are the different steps included in the workshop:
- Standard Winform + API NET Chat App
- Add Azure OpenAI GPT-4o to support chat (text)
- Add Azure OpenAI GPT-4o to support chat + image (text)
- Add Phi-3 to support chat using ONNX (text)
- Add Phi-3 to support chat + image using ONNX (text)
- Add Phi-3 to support chat using Ollama in docker(text)
- Add Cache using Semantic Memory, local in Memory
- Add Cache using Semantic Memory, store in Azure AI Search
- Add RAG using Azure AI Search
- Add Aspire Dashboard using OTLP endpoint
- Use an external API using native functions
Before running the sample, ensure you have the following installed:
-
.NET 8: Make sure you have the latest version of .NET installed on your machine.
-
Visual Studio or Visual Studio Code: You will need an IDE or code editor capable of running .NET projects. Visual Studio or Visual Studio Code are recommended.
-
Azure OpenAI Services: To GPT-4o as the model to support the chat, you need to have access to Azure OpenAI Services and create and deploy a GPT-4o model.
-
Ollama: To use Phi-3 as local model with Ollama, you need to have ollama installed.
-
Docker Desktop: To use Phi-3 as local model with Ollama, you need to have docker installed.
-
Ollama in Docker. Follow the link steps to install ollama in Docker.
-
Aspire Dashboard in Docker. Follow the link steps to install the Aspire Dashboard in Docker.
-
-
Super Hero API: To use the native functions demo, get a free key for the SuperHero API.
The chat-server
project uses .NET User Secrets to access remote resources like Azure OpenAI Services or Azure AI Search.
Follow these steps to add the secrets to the project.
-
Open a terminal and navigate to the
chat-server
project.cd .\src\chat-server\
-
Run the following command with the correct values
dotnet user-secrets init dotnet user-secrets set "AZURE_OPENAI_MODEL" "< Azure OpenAI Model, ie: gpt-4o >" dotnet user-secrets set "AZURE_OPENAI_ENDPOINT" "< Azure OpenAI Endpoint >" dotnet user-secrets set "AZURE_OPENAI_APIKEY" "< Azure OpenAI Key >" dotnet user-secrets set "AZURE_OPENAI_ADA02" "< Azure OpenAI Embeddings model, ie: text-embedding-ada-002 >" dotnet user-secrets set "AZURE_AISEARCH_ENDPOINT" "< Azure AI Search Endpoint >" dotnet user-secrets set "AZURE_AISEARCH_APIKEY" "< Azure AI Search ApiKey >" dotnet user-secrets set "AZURE_AISEARCH_INDEXNAME" "< Azure AI Search IndexName for RAG >" dotnet user-secrets set "OTLP_ENDPOINT" "< OTLP ENDPOINT, ie: http://localhost:4317 >" dotnet user-secrets set "SUPERHERO_APIKEY" "< super hero api key >"
-
Create a local folder to store the Phi-3 local model. In example:
C:\phi3\models
. -
Download the phi3-mini-4k-instruct-onnx model to your local machine:
# navigate to the folder to store the models cd c:\phi3\models # add support for lfs git lfs install # clone and download mini 4K instruct model git clone https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx # clone and download vision 128K model git clone https://huggingface.co/microsoft/Phi-3-vision-128k-instruct-onnx-cpu
Important: The current demos are designed to use the ONNX versions of the model. The previous steps clone the following models.
Run this command to get the Aspire dashboard up and running in docker:
docker run --rm -it -p 18888:18888 -p 4317:18889 -d --name aspire-dashboard mcr.microsoft.com/dotnet/aspire-dashboard:8.0.0
Run this command to host ollama in Docker:
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
Coming soon ...
- Phi-3 Microsoft Blog
- Phi-3 Technical Report
- Phi-3 Cookbook
- Using Phi-3 & C# with ONNX for text and vision samples
- Generative AI for beginners
- Semantic Kernel main repository
- Smart Components - Local Embeddings
- Aspire Dashboard
- Snippet Generator
- WinForm Chat - inspirational project
👤 Bruno Capuano
- Website: https://elbruno.com
- Twitter: @elbruno
- Github: @elbruno
- LinkedIn: @elbruno
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
Copyright © 2024 Bruno Capuano.
This project is MIT licensed.