Skip to content

Microsoft.Extensions.AI Integration

Cross-SDK comparison

See the centralized MEAI documentation for feature matrices and comparisons across all tryAGI SDKs.

The Sightengine SDK provides AIFunction tool wrappers compatible with Microsoft.Extensions.AI. These tools can be used with any IChatClient to give AI models access to Sightengine's image and text moderation, AI-generated image detection, and username validation.

Installation

1
dotnet add package Sightengine

Available Tools

Method Tool Name Description
AsModerateImageTool() ModerateImage Moderate an image URL for nudity, violence, gore, weapons, drugs, and more
AsDetectAiGeneratedTool() DetectAiGeneratedImage Detect whether an image was AI-generated
AsModerateTextTool() ModerateText Moderate text for profanity, personal information, and links
AsValidateUsernameTool() ValidateUsername Validate a username for profanity and misleading content

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Sightengine;
using Microsoft.Extensions.AI;

var sightengineClient = new SightengineClient(
    apiKey: Environment.GetEnvironmentVariable("SIGHTENGINE_API_USER")! + ":" +
            Environment.GetEnvironmentVariable("SIGHTENGINE_API_SECRET")!);

var options = new ChatOptions
{
    Tools =
    [
        sightengineClient.AsModerateImageTool(),
        sightengineClient.AsDetectAiGeneratedTool(),
        sightengineClient.AsModerateTextTool(),
        sightengineClient.AsValidateUsernameTool(),
    ],
};

IChatClient chatClient = /* your chat client */;

var messages = new List<ChatMessage>
{
    new(ChatRole.User, "Check if this image is AI-generated: https://example.com/photo.jpg"),
};

while (true)
{
    var response = await chatClient.GetResponseAsync(messages, options);
    messages.AddRange(response.ToChatMessages());

    if (response.FinishReason == ChatFinishReason.ToolCalls)
    {
        var results = await response.CallToolsAsync(options);
        messages.AddRange(results);
        continue;
    }

    Console.WriteLine(response.Text);
    break;
}