Created
April 13, 2026 15:14
-
-
Save wullemsb/5201e1ad8dbbf56cccd806d485de5eb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Microsoft.Agents.AI.DevUI; | |
| using Microsoft.Agents.AI.Hosting; | |
| using Microsoft.AspNetCore.Mvc.ModelBinding; | |
| using Microsoft.Extensions.AI; | |
| using OllamaSharp; | |
| using OpenTelemetry.Resources; | |
| using System.Net; | |
| var builder = WebApplication.CreateBuilder(args); | |
| // ── 1. Configure the chat client (Ollama endpoint) ────────── | |
| // Configuration - Ollama endpoint and model selection | |
| var endpoint = "http://localhost:11434"; // Default Ollama endpoint | |
| var modelName = "llama3.2"; // Model to use for AI responses | |
| using OllamaApiClient chatClient = new(new Uri(endpoint), modelName); | |
| builder.Services.AddChatClient(chatClient); | |
| // ── 2. Register agents ────────────────────────────────────────────── | |
| builder | |
| .AddAIAgent( | |
| "WeatherBot", | |
| "You are a friendly weather assistant. Always ask the user for their city if they haven't provided it." | |
| ); | |
| // ── 3. Register OpenAI-compatible Responses + Conversations APIs ──── | |
| // These are required by DevUI to intercept and display traffic. | |
| builder.Services.AddOpenAIResponses(); | |
| builder.Services.AddOpenAIConversations(); | |
| var app = builder.Build(); | |
| // ── 4. Map the OpenAI API endpoints ───────────────────────────────── | |
| app.MapOpenAIResponses(); | |
| app.MapOpenAIConversations(); | |
| // ── 5. Map DevUI (development only) ────────────────────────────────── | |
| if (app.Environment.IsDevelopment()) | |
| { | |
| app.MapDevUI(); | |
| } | |
| app.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment