--- name: azure-functions-genai description: >- Guides the design, implementation, and debugging of Azure Functions v4 (.NET 8/10 Isolated Worker) using the official Google.GenAI C# SDK for serverless AI endpoints. --- # Azure Functions & Google.GenAI C# SDK Skill Use this skill when developing, updating, or testing the C# serverless API endpoints located in `api/`. --- ## 1. Solution Architecture The backend consists of an **Azure Functions v4 Isolated Worker** targeting **.NET 8.0**: - Project file: `api/api.csproj` - Runtime: `Microsoft.Azure.Functions.Worker` 2.50+ & `Google.GenAI` 1.20+ - Host configuration: `api/host.json` - Application Insights integration: `Microsoft.ApplicationInsights.WorkerService` --- ## 2. Google.GenAI C# SDK Integration Patterns ### 2.1 Namespaces & Types ```csharp using Google.GenAI; using Google.GenAI.Types; using Type = Google.GenAI.Types.Type; // Disambiguate with System.Type ``` ### 2.2 Client Initialization ```csharp var apiKey = System.Environment.GetEnvironmentVariable("GEMINI_API_KEY"); var client = new Client(apiKey: apiKey); ``` ### 2.3 Structured Output Generation (JSON Schema) ```csharp var schema = new Schema { Type = Type.Object, Properties = new Dictionary { { "distortionsIdentified", new Schema { Type = Type.Array, Items = new Schema { Type = Type.String } } }, { "techniquesUsed", new Schema { Type = Type.Array, Items = new Schema { Type = Type.String } } }, { "clinicalInsight", new Schema { Type = Type.String } }, { "feedbackType", new Schema { Type = Type.String, Enum = new List { "Constructive", "Positive", "Neutral" } } } }, Required = new List { "distortionsIdentified", "techniquesUsed", "clinicalInsight", "feedbackType" } }; var response = await client.Models.GenerateContentAsync( model: "gemini-2.5-flash", contents: promptContent, config: new GenerateContentConfig { SystemInstruction = new Content { Parts = new List { new Part { Text = systemInstruction } } }, ResponseMimeType = "application/json", ResponseSchema = schema }); ``` --- ## 3. Endpoints Matrix | Route | HTTP Method | Function Name | Purpose | |:---|:---|:---|:---| | `/api/chat` | `POST` | `ChatProgression` | Headless roleplay progression with strict anti-meta guardrails | | `/api/analysis` | `POST` | `ClinicalAnalysis` | Real-time clinical supervisor turn evaluation | | `/api/scenario/generate` | `POST` | `GenerateScenario` | Dynamic CBT roleplay scenario generation | --- ## 4. Local Build & Test Verification ```bash # Build the C# API project dotnet build api/api.csproj # Run local functions host (requires Azure Functions Core Tools) func start --csharp --prefix api ```