A comprehensive collection of code templates and generated samples for Azure OpenAI SDK implementations across multiple programming languages. This repository provides a robust pipeline for generating, validating, and maintaining consistent code samples for Azure OpenAI services.
This repository serves as the hub for Azure OpenAI code sample templates that automatically generate language-specific implementations. Using the Caleuche CLI tool, templates are transformed into working code samples with proper validation and testing.
- C# (.NET 9.0) - Full support with validation pipeline
- Python - Full support with validation pipeline
- Java - Full support with validation pipeline
- Go - Full support with validation pipeline
- JavaScript/Node.js - Template support available
- Audio Transcription (sync/async)
- Chat Completion (basic, streaming, conversation, structured outputs)
- Chat with Vision (image input, reasoning)
- Embeddings (sync/async)
- Image Generation (sync/async)
- Response Handling (basic, streaming, file input, image input)
├── ci/ # Azure DevOps pipeline configuration
├── samples/ # Template source files
│ ├── input-data.yaml # Configuration for generating samples
│ └── {sample-scenario-name} # Individual sample templates
│ ├── csharp/ # C# templates
│ ├── python/ # Python templates
│ ├── {etc.}/ # templates other supported languages
├── scripts/ # Build and validation scripts
├── validation-config-defaults/ # Language-specific validation configs
├── generated-samples/ # Output folder when run generation sequence is run (locally or pipeline)
│ ├── csharp/ # Generated C# samples
│ ├── python/ # Generated Python samples
│ └── {etc.}/ # Generated Java samples
- Dev Container: This repository includes a complete dev container setup with all required tools
- Manual Setup: If not using dev containers, you'll need:
- .NET SDK 9.x
- Python 3.11+
- Java 17+ (for Java samples)
- Node.js 14+ (for tooling)
- Azure CLI
-
Clone the repository:
git clone https://github.com/Azure-Samples/template-samples.git cd template-samples
-
Open in dev container (recommended):
- Use VS Code with Remote-Containers extension
- Open Command Palette → "Remote-Containers: Reopen in Container"
-
Generate samples:
npm install -g @caleuche/cli che batch samples/input-data.yaml
-
[COMING SOON] View samples in the web UI:
cd mockUI npm install npm start
-
Create template directory:
mkdir -p samples/my-new-sample-scenario/{csharp,python,java,go}
-
Create template files:
- Add
sample.{language}.template
files for each supported language - Add accompanying
sample.yaml
template input configuration to populate templated syntax with dynamic content, e.g.<%= endpoint %>
- Add
-
Configure sample generation:
- Add entry to
samples/input-data.yaml
- Define input parameters and output paths
- Add entry to
-
Optional: Add validation overrides:
- Create
.validation-config.json
in language directories - Override default build/validation steps if needed
- Create
Templates use EJS-style syntax with language-specific helpers:
// C# template example
using Azure.AI.OpenAI;
public class Sample {
public static async Task Main(string[] args) {
var endpoint = "<%= endpoint %>";
var deploymentName = "<%= deploymentName %>";
// ... rest of implementation
}
}
See more on the Caleuche repo or in the existing templates under samples
Each language has default validation steps defined in validation-config-defaults/
:
{
"language": "csharp",
"framework": "net9.0",
"buildSteps": [
"dotnet restore",
"dotnet build"
],
"validationLevel": "compile-only"
}
The Azure DevOps pipeline automatically:
- Generates samples from templates using Caleuche CLI
- Detects changes to any modified samples
- Validates samples for each language:
- Compiles code to ensure syntax correctness
- Runs static analysis and formatting checks
- Validates proper SDK usage patterns
- Publishes artifacts of all generated samples that pass validation
The mockUI/
directory contains a clean web interface for viewing and testing generated samples:
- Multi-language support with syntax highlighting
- Scenario selection via dropdown
- Real-time updates when samples change
- Copy-to-clipboard functionality