diff --git a/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/GHModel.dotNET.AI.Workflow.DevUI.csproj b/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/GHModel.dotNET.AI.Workflow.DevUI.csproj index f1aa552..120cc05 100644 --- a/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/GHModel.dotNET.AI.Workflow.DevUI.csproj +++ b/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/GHModel.dotNET.AI.Workflow.DevUI.csproj @@ -5,21 +5,14 @@ enable enable - - - - - - - - - - - - - + + + + + + diff --git a/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/Program.cs b/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/Program.cs index 6134424..6294d8d 100644 --- a/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/Program.cs +++ b/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/Program.cs @@ -1,28 +1,14 @@ -// using System.ComponentModel; -// using Azure.AI.OpenAI; -// using Azure.Identity; -// using Microsoft.Agents.AI; -// using Microsoft.Agents.AI.DevUI; -// using Microsoft.Agents.AI.Hosting; -// using Microsoft.Agents.AI.Workflows; -// using Microsoft.Extensions.AI; - using System; -using System.ComponentModel; using System.ClientModel; -using Azure.Identity; using DotNetEnv; using OpenAI; - using Microsoft.Agents.AI; using Microsoft.Agents.AI.DevUI; using Microsoft.Agents.AI.Hosting; using Microsoft.Agents.AI.Workflows; -using Microsoft.Agents.AI.Workflows.Reflection; using Microsoft.Extensions.AI; - namespace GHModel.dotNET.AI.Workflow.DevUI; /// @@ -53,26 +39,27 @@ internal static class Program private static void Main(string[] args) { // Load environment variables from .env file - Env.Load("../../../../.env"); + Env.Load("../../.env"); var builder = WebApplication.CreateBuilder(args); - // Set up the Azure OpenAI client - var github_endpoint = Environment.GetEnvironmentVariable("GITHUB_ENDPOINT") ?? throw new InvalidOperationException("GITHUB_ENDPOINT is not set."); - var github_model_id = "openai/gpt-5"; - var github_token = Environment.GetEnvironmentVariable("GITHUB_TOKEN") ?? throw new InvalidOperationException("GITHUB_TOKEN is not set."); + var githubEndpoint = GetRequiredEnvironmentVariable("GITHUB_ENDPOINT"); + var githubModelId = GetRequiredEnvironmentVariable("GITHUB_MODEL_ID"); + var githubToken = GetRequiredEnvironmentVariable("GITHUB_TOKEN"); var openAIOptions = new OpenAIClientOptions() { - Endpoint = new Uri(github_endpoint) + Endpoint = new Uri(githubEndpoint) }; - - var openAIClient = new OpenAIClient(new ApiKeyCredential(github_token), openAIOptions); - - var chatClient = openAIClient.GetChatClient(github_model_id).AsIChatClient(); + var openAIClient = new OpenAIClient(new ApiKeyCredential(githubToken), openAIOptions); + var chatClient = openAIClient.GetChatClient(githubModelId).AsIChatClient(); builder.Services.AddChatClient(chatClient); + if (builder.Environment.IsDevelopment()) + { + builder.Services.AddDevUI(); + } // Register sample agents with tools builder.AddAIAgent("GPTAssistant", "You are a helpful assistant. Answer questions concisely and accurately."); @@ -101,7 +88,8 @@ Consider suggestions when refining an idea. builder.AddWorkflow("gh-model-workflow", (sp, key) => { - var agents = new List() { reviewerAgentBuilder, frontDeskAgentBuilder }.Select(ab => sp.GetRequiredKeyedService(ab.Name)); + var agents = new[] { frontDeskAgentBuilder, reviewerAgentBuilder } + .Select(agentBuilder => sp.GetRequiredKeyedService(agentBuilder.Name)); return AgentWorkflowBuilder.BuildSequential(workflowName: key, agents: agents); }).AddAsAIAgent(); @@ -111,19 +99,26 @@ Consider suggestions when refining an idea. var app = builder.Build(); - app.UseHttpsRedirection(); - app.MapOpenAIResponses(); app.MapOpenAIConversations(); if (builder.Environment.IsDevelopment()) { app.MapDevUI(); + Console.WriteLine("DevUI is available at: http://localhost:50518/devui"); } - Console.WriteLine("DevUI is available at: http://localhost:50518/devui"); Console.WriteLine("OpenAI Responses API is available at: http://localhost:50518/v1/responses"); Console.WriteLine("Press Ctrl+C to stop the server."); app.Run(); } + + private static string GetRequiredEnvironmentVariable(string name) + { + var value = Environment.GetEnvironmentVariable(name); + return !string.IsNullOrWhiteSpace(value) + ? value + : throw new InvalidOperationException( + $"{name} is not set. Add it to 09.Cases/GHModel.AI/.env or set it in your environment."); + } } diff --git a/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/Properties/launchSettings.json b/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/Properties/launchSettings.json index 0bac70a..d2d730d 100644 --- a/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/Properties/launchSettings.json +++ b/09.Cases/GHModel.AI/GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI/Properties/launchSettings.json @@ -1,6 +1,6 @@ { "profiles": { - "Dev_UI_Applcaiton": { + "Dev_UI_Application": { "commandName": "Project", "launchUrl": "devui", "launchBrowser": true, diff --git a/09.Cases/GHModel.AI/README.md b/09.Cases/GHModel.AI/README.md index 3eb54d8..ae5f832 100644 --- a/09.Cases/GHModel.AI/README.md +++ b/09.Cases/GHModel.AI/README.md @@ -72,7 +72,7 @@ The project uses a dual-agent sequential workflow: ### Prerequisites -- Python 3.10+ / .NET 8.0+ +- Python 3.10+ / .NET 10.0+ - GitHub Models API access (or Azure OpenAI / OpenAI) - Docker (optional, for running Aspire Dashboard) @@ -85,12 +85,15 @@ cd GHModel.AI ### 2. Configure Environment Variables -Create a `.env` file in each example directory: +Set these environment variables in your shell or in the `.env` location used by +the example you are running. The .NET DevUI example loads +`09.Cases/GHModel.AI/.env`: ```env -GITHUB_ENDPOINT=https://models.inference.ai.azure.com +GITHUB_ENDPOINT=https://models.github.ai/inference +# Fine-grained PAT with "Models: read" permission GITHUB_TOKEN=your_github_token -GITHUB_MODEL_ID=gpt-4o +GITHUB_MODEL_ID=openai/gpt-4.1-mini ``` --- @@ -230,10 +233,13 @@ python main.py ```bash cd GHModel.dotNET.AI/GHModel.dotNET.AI.Workflow.DevUI dotnet run -# DevUI: https://localhost:50516/devui -# OpenAI API: https://localhost:50516/v1/responses +# DevUI: http://localhost:50518/devui +# OpenAI API: http://localhost:50518/v1/responses ``` +Select `gh-model-workflow` in DevUI to run the sequential FrontDesk and +Concierge workflow. + #### Code Snippets ```python @@ -244,9 +250,23 @@ serve(entities=[workflow], port=8090, auto_open=True, tracing_enabled=True) ```csharp // .NET — ASP.NET Core integration +if (builder.Environment.IsDevelopment()) +{ + builder.Services.AddDevUI(); +} builder.AddAIAgent("FrontDesk", FrontDeskAgentInstructions); builder.AddWorkflow("gh-model-workflow", ...); -app.MapDevUI(); + +builder.Services.AddOpenAIResponses(); +builder.Services.AddOpenAIConversations(); + +app.MapOpenAIResponses(); +app.MapOpenAIConversations(); + +if (app.Environment.IsDevelopment()) +{ + app.MapDevUI(); +} ``` --- @@ -390,4 +410,4 @@ This project is licensed under the [MIT License](LICENSE). ## 🤝 Contributing -Contributions are welcome! Feel free to submit Issues and Pull Requests. For questions or suggestions, please open an issue on GitHub. \ No newline at end of file +Contributions are welcome! Feel free to submit Issues and Pull Requests. For questions or suggestions, please open an issue on GitHub.