C# Implementation using Optimizely.Opal.Tools SDK v0.4.0
A production-ready Opal custom tool that generates natural, AI-like product descriptions based on product name, part number, and attributes.
- β
Official Optimizely Opal SDK Integration (
Optimizely.Opal.Toolsv0.4.0) - β Natural AI-like Descriptions - Dynamically generated, professional content
- β Type & Tone Parameters - Customize output for ecommerce, technical, or marketing
- β Clean Architecture - Separation of concerns with Models, Services, and Tools layers
- β Dependency Injection - Testable, maintainable code structure
- β No Character Limits - Generate complete, natural descriptions
- β Auto-Generated Discovery - Opal SDK handles endpoint generation
- .NET 8.0 SDK or later
- Optimizely Opal instance (for testing)
cd csharp
dotnet restore
dotnet build
dotnet runServer starts at: http://localhost:5000
curl http://localhost:5000/discoverycurl -X POST http://localhost:5000/tools/product-description-generator \
-H "Content-Type: application/json" \
-d '{
"parameters": {
"ProductName": "DEWALT 20V Acrylic Dispenser 101 28 oz",
"PartNumber": "211DCE595D1",
"Attributes": [
"Brand: DEWALT",
"Battery Voltage (V): 20",
"Capacity: 28 oz.",
"Cordless / Corded: Cordless"
],
"Type": "ecommerce",
"Tone": "professional"
}
}'csharp/
βββ Program.cs # Application entry point & DI configuration
βββ Models/
β βββ ProductDescriptionParameters.cs # Request parameters (DTOs)
βββ Services/
β βββ IDescriptionGenerationService.cs # Service interface
β βββ DescriptionGenerationService.cs # Business logic implementation
βββ Tools/
βββ ProductDescriptionGeneratorTool.cs # Opal tool with [OpalTool] attribute
- Separation of Concerns: Each layer has a single responsibility
- Dependency Injection: Services injected via constructor
- Interface-Based Design: Easy to test and extend
- SOLID Principles: SRP, OCP, LSP, ISP, DIP all applied
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| ProductName | string | Yes | Name of the product | "DEWALT 20V Acrylic Dispenser" |
| PartNumber | string | Yes | Product part number or SKU | "211DCE595D1" |
| Attributes | array | Yes | Product attributes, features, specifications | ["Brand: DEWALT", "Voltage: 20V"] |
| Type | string | No | Content category | "ecommerce", "technical", "marketing", "general" |
| Tone | string | No | Description tone | "professional", "casual", "enthusiastic" |
- Type:
general(if not provided) - Tone:
professional(if not provided)
{
"parameters": {
"ProductName": "DEWALT 20V Acrylic Dispenser 101 28 oz",
"PartNumber": "211DCE595D1",
"Attributes": [
"Brand: DEWALT",
"Battery Voltage (V): 20",
"Capacity: 28 oz.",
"Cartridge Type: 27-28 oz. Adhesive 10:1",
"Cordless / Corded: Cordless"
],
"Type": "ecommerce",
"Tone": "professional"
}
}{
"content": "The DEWALT 20V Acrylic Dispenser 101 28 oz (Part# 211DCE595D1) delivers powerful, reliable cordless performance for professional applications. Features include capacity: 28 oz., 27-28 oz. Adhesive 10:1. Built with DEWALT quality and reliability. Designed for demanding applications.",
"productName": "DEWALT 20V Acrylic Dispenser 101 28 oz",
"partNumber": "211DCE595D1",
"attributeCount": 5,
"type": "ecommerce",
"tone": "professional"
}"delivers powerful cordless performance."
"delivers powerful, reliable cordless performance for professional applications."
// Mock the service
var mockService = new Mock<IDescriptionGenerationService>();
mockService
.Setup(s => s.GenerateProductDescription(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<List<string>>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Returns("Test description");
// Inject into tool
var tool = new ProductDescriptionGeneratorTool(mockService.Object);Use PowerShell (Windows):
.\examples\test.ps1Or use the test-requests.json with Postman/Insomnia.
- Optimizely.Opal.Tools v0.4.0 - Official Opal SDK
- Microsoft.AspNetCore.OpenApi v8.0.0 - OpenAPI support
- Swashbuckle.AspNetCore v6.8.0 - Swagger documentation
One-Command Deployment:
.\deploy-azure.ps1See QUICK_DEPLOY.md for details.
Manual Options:
- π Complete Azure Deployment Guide
- π Automated GitHub Actions deployment
- π³ Container Registry deployment
Pricing Tiers:
- Free (F1): Testing only
- Basic (B1): ~$13/month - Recommended
- Premium (P1V2): ~$73/month - Production with auto-scaling
dotnet run --project csharp/ProductDescriptionGenerator.csprojdotnet publish -c Release -o ./publishdocker build -t product-description-generator ./csharp
docker run -p 5000:8080 product-description-generator- C# Clean Architecture README - Detailed architecture documentation
- SDK Integration Guide - How the SDK is integrated
| Endpoint | Method | Description |
|---|---|---|
/discovery |
GET | Tool definition and parameters (auto-generated by SDK) |
/tools/product-description-generator |
POST | Execute tool (auto-generated by SDK) |
- Optimizely Opal Tools SDK
- Optimizely Academy - Building Simple Tools
- Optimizely Support - Create Custom Tools
MIT License - See LICENSE file
This is a reference implementation. Feel free to use it as a starting point for your own Opal custom tools!
Built with Optimizely Opal SDK | Clean Architecture | Production Ready