Zonit.Extensions.Ai.Prompts 1.0.55

dotnet add package Zonit.Extensions.Ai.Prompts --version 1.0.55
                    
NuGet\Install-Package Zonit.Extensions.Ai.Prompts -Version 1.0.55
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zonit.Extensions.Ai.Prompts" Version="1.0.55" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zonit.Extensions.Ai.Prompts" Version="1.0.55" />
                    
Directory.Packages.props
<PackageReference Include="Zonit.Extensions.Ai.Prompts" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zonit.Extensions.Ai.Prompts --version 1.0.55
                    
#r "nuget: Zonit.Extensions.Ai.Prompts, 1.0.55"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zonit.Extensions.Ai.Prompts@1.0.55
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zonit.Extensions.Ai.Prompts&version=1.0.55
                    
Install as a Cake Addin
#tool nuget:?package=Zonit.Extensions.Ai.Prompts&version=1.0.55
                    
Install as a Cake Tool

Zonit.Extensions.Ai

A .NET library for integrating with multiple AI providers (OpenAI, Anthropic Claude, X Grok, Google Gemini) with Scriban templating, type-safe prompts, and built-in resilience.

Installation

Install-Package Zonit.Extensions.Ai

Quick Start

// 1. Register services
services.AddAi(options =>
{
    options.OpenAiKey = "your-openai-api-key";
    options.AnthropicKey = "your-anthropic-api-key";
    options.XKey = "your-x-api-key";
    options.GoogleKey = "your-google-api-key";
});

// 2. Create a prompt with Scriban templating
public class TranslatePrompt : PromptBase<TranslateResponse>
{
    public required string Content { get; set; }
    public required string Language { get; set; }

    public override string Prompt => @"
Translate the following text into {{ language }}:
{{ content }}
";
}

// 3. Generate response
var result = await aiClient.GenerateAsync(
    new TranslatePrompt { Content = "Hello!", Language = "Polish" }, 
    new GPT51()
);
Console.WriteLine(result.Value.TranslatedText);

Supported Models

OpenAI

Model Class Features
GPT-5, GPT-5.1 GPT5, GPT51, GPT51Chat Text, Vision, Image output
GPT-5 Mini/Nano GPT5Mini, GPT5Nano Cost-effective
GPT-4.1 GPT41, GPT41Mini, GPT41Nano Latest GPT-4
O3, O4-mini O3, O4Mini Reasoning models
GPT-4o Search GPT4oSearch Web search
DALL�E GPTImage1, GPTImage1Mini Image generation

Anthropic (Claude)

Model Class Features
Sonnet 4.5 Sonnet45 Balanced, prompt caching
Opus 4, 4.1 Opus4, Opus41 Most capable
Haiku 4.5 Haiku45 Fast, cost-effective

X (Grok)

Model Class Features
Grok-4 Grok4 Web search native
Grok-4.1 Grok41FastReasoning, Grok41FastNonReasoning Advanced reasoning
Grok-3 Grok3, Grok3Fast, Grok3Mini, Grok3MiniFast Previous gen
GrokCodeFast1 GrokCodeFast1 Code specialized

Scriban Templating

Properties are automatically available in templates (PascalCase ? snake_case):

public class MyPrompt : PromptBase<MyResponse>
{
    public string Name { get; set; }           // {{ name }}
    public List<string> Items { get; set; }    // {{ items }}
    public bool IsActive { get; set; }         // {{ is_active }}

    public override string Prompt => @"
Hello {{ name }}!

{{~ if is_active ~}}
Your items:
{{~ for item in items ~}}
- {{ item }}
{{~ end ~}}
{{~ end ~}}
";
}

Whitespace control: {{~ removes whitespace before, ~}} removes after.

Excluded properties: Tools, ToolChoice, UserName, Files, ModelType

AI Tools

Web Search (OpenAI)

public class SearchPrompt : PromptBase<SearchResponse>
{
    public required string Query { get; set; }
    public override string Prompt => "Search for: {{ query }}";
    
    public override IReadOnlyList<ITool> Tools => 
        new[] { new WebSearchTool { ContextSize = WebSearchTool.ContextSizeType.High } };
    public override ToolsType ToolChoice => ToolsType.WebSearch;
}
var grok = new Grok4
{
    WebSearch = new Search
    {
        Mode = ModeType.Always,           // Always, Never, Auto
        Citations = true,
        MaxResults = 20,
        FromDate = DateTime.UtcNow.AddMonths(-6),
        ToDate = DateTime.UtcNow,
        Language = "en",                  // ISO 639-1
        Region = "US",                    // ISO 3166-1 alpha-2
        Sources = new ISearchSource[]
        {
            new WebSearchSource
            {
                AllowedWebsites = new[] { "wikipedia.org", "github.com" },
                SafeSearch = true
            },
            new XSearchSource
            {
                IncludedXHandles = new[] { "OpenAI", "anthropaborAI" }
            }
        }
    }
};
public class DocumentPrompt : PromptBase<AnalysisResult>
{
    public override IReadOnlyList<IFile> Files { get; set; }
    public override IReadOnlyList<ITool> Tools => new[] { new FileSearchTool() };
    public override ToolsType ToolChoice => ToolsType.FileSearch;
    
    public override string Prompt => "Analyze the documents";
}

File Management

// Create from path
var file = await FileModel.CreateFromFilePathAsync("image.jpg");

// Create from bytes
var file = new FileModel("doc.pdf", "application/pdf", bytes);

// Save
await file.SaveToFileAsync("output.jpg");

Supported formats: JPG, PNG, GIF, WebP, PDF, DOC/DOCX, XLS/XLSX, PPT/PPTX, TXT, JSON, CSV, XML

Image Generation

public class ImagePrompt : PromptBase<IFile>
{
    public required string Description { get; set; }
    public override string Prompt => "Generate: {{ description }}";
}

var result = await aiClient.GenerateAsync(
    new ImagePrompt { Description = "A sunset over mountains" },
    new GPTImage1
    {
        Quality = GPTImage1.QualityType.High,    // Standard, High
        Size = GPTImage1.SizeType.Landscape,      // Square, Portrait, Landscape
        Style = GPTImage1.StyleType.Natural       // Natural, Vivid
    }
);
await result.Value.SaveToFileAsync("sunset.png");

Model Configuration

// Text models
var model = new GPT51
{
    MaxTokens = 4000,
    Temperature = 0.7,
    TopP = 0.9,
    StoreLogs = true
};

// Reasoning models
var reasoning = new O3
{
    Reason = OpenAiReasoningBase.ReasonType.High,
    ReasonSummary = OpenAiReasoningBase.ReasonSummaryType.Detailed
};

// Check capabilities
if (model.SupportedTools.HasFlag(ToolsType.WebSearch)) { /* ... */ }
if (model.SupportedFeatures.HasFlag(FeaturesType.Streaming)) { /* ... */ }

Metadata & Costs

var result = await aiClient.GenerateAsync(prompt, model);

Console.WriteLine($"Tokens: {result.MetaData.InputTokenCount} in / {result.MetaData.OutputTokenCount} out");
Console.WriteLine($"Cost: ${result.MetaData.PriceTotal:F6}");
Console.WriteLine($"Duration: {result.MetaData.Duration.TotalSeconds:F2}s");

JSON Schema Responses

The library auto-generates JSON Schema from response classes:

[Description("Translation result")]
public class TranslateResponse
{
    [Description("Translated text")]
    public string TranslatedText { get; set; }
    
    [Description("Detected source language")]
    public string DetectedLanguage { get; set; }
}

Resilience Configuration

Uses Microsoft.Extensions.Http.Resilience with unified config for all providers:

{
  "Ai": {
    "Resilience": {
      "HttpClientTimeout": "00:30:00",
      "TotalRequestTimeout": "00:25:00",
      "AttemptTimeout": "00:20:00",
      "Retry": {
        "MaxRetryAttempts": 3,
        "BaseDelay": "00:00:02",
        "MaxDelay": "00:00:30",
        "UseJitter": true
      },
      "CircuitBreaker": {
        "FailureRatio": 0.5,
        "MinimumThroughput": 10,
        "SamplingDuration": "00:02:00",
        "BreakDuration": "00:00:30"
      }
    }
  }
}

Error Handling

try
{
    var result = await aiClient.GenerateAsync(prompt, model);
}
catch (JsonException ex)
{
    // JSON parsing error
}
catch (InvalidOperationException ex)
{
    // API error (after retries exhausted)
}

Architecture

Clean Architecture with layered separation:

  • Abstractions - Interfaces and contracts
  • Domain - Models and business logic
  • Application - Services, configuration, Scriban prompt service
  • Infrastructure - Provider implementations (OpenAI, Anthropic, X, Google)
  • LLM - Model definitions and tools
  • Prompts - Example templates
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.55 30 1/15/2026
1.0.54 431 12/8/2025
1.0.53 191 11/24/2025
1.0.52 237 11/22/2025
1.0.51 403 11/20/2025
1.0.50 397 11/18/2025
1.0.26 242 8/27/2025
1.0.25 254 8/7/2025
1.0.24 261 8/7/2025
1.0.23 157 7/28/2025
1.0.22 149 7/28/2025
1.0.21 175 7/27/2025
1.0.20 150 7/12/2025
1.0.19 139 7/11/2025
1.0.18 180 7/10/2025
1.0.17 172 7/10/2025
1.0.16 170 7/10/2025
1.0.15 180 7/10/2025
1.0.14 184 7/8/2025
1.0.13 176 7/8/2025
1.0.12 181 7/7/2025
1.0.11 129 7/4/2025
1.0.10 131 7/4/2025
1.0.9 155 7/4/2025
1.0.8 175 7/4/2025
1.0.7 179 7/4/2025
1.0.6 192 7/3/2025
1.0.5 183 7/3/2025
1.0.4 182 7/3/2025
1.0.3 172 7/3/2025
1.0.2 187 7/3/2025
1.0.1 184 7/3/2025
1.0.0 193 7/3/2025