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 SiliconFlow SDK provides AIFunction tool wrappers compatible with Microsoft.Extensions.AI. These tools can be used with any IChatClient to give AI models access to SiliconFlow's document reranking, image generation, model listing, and account information.

Installation

1
dotnet add package SiliconFlow

Available Tools

Method Tool Name Description
AsRerankTool() SiliconFlow_Rerank Rerank documents by relevance to a search query
AsTextToImageTool() SiliconFlow_TextToImage Generate images from text prompts using FLUX/Stable Diffusion models
AsListModelsTool() SiliconFlow_ListModels List all available AI models on the platform
AsGetUserInfoTool() SiliconFlow_GetUserInfo Get account information including balance and status

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
using SiliconFlow;
using Microsoft.Extensions.AI;

var siliconFlowClient = new SiliconFlowClient(
    apiKey: Environment.GetEnvironmentVariable("SILICONFLOW_API_KEY")!);

var options = new ChatOptions
{
    Tools =
    [
        siliconFlowClient.AsRerankTool(),
        siliconFlowClient.AsTextToImageTool(),
        siliconFlowClient.AsListModelsTool(),
        siliconFlowClient.AsGetUserInfoTool(),
    ],
};

IChatClient chatClient = /* your chat client */;

var messages = new List<ChatMessage>
{
    new(ChatRole.User, "What models are available on SiliconFlow?"),
};

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;
}