Microsoft.Extensions.AI Integration
The Roboflow SDK provides AIFunction tool wrappers from Microsoft.Extensions.AI, allowing you to use Roboflow computer vision inference as tools with any IChatClient.
Installation
| dotnet add package Roboflow
|
Use AsObjectDetectionTool() to detect objects in images using a Roboflow model:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 | using Roboflow;
using Microsoft.Extensions.AI;
var roboflowClient = new RoboflowClient(apiKey: Environment.GetEnvironmentVariable("ROBOFLOW_API_KEY")!);
var detectionTool = roboflowClient.AsObjectDetectionTool(confidence: 0.5);
// Use with any IChatClient
IChatClient chatClient = /* your chat client */;
var options = new ChatOptions
{
Tools = [detectionTool],
};
var response = await chatClient.GetResponseAsync(
"Detect all objects in this image: https://example.com/photo.jpg",
options);
|
Use AsClassificationTool() to classify images:
| var classificationTool = roboflowClient.AsClassificationTool(confidence: 0.5);
var options = new ChatOptions
{
Tools = [classificationTool],
};
|
Use AsOcrTool() to extract text from images using the DocTR OCR model:
| var ocrTool = roboflowClient.AsOcrTool();
var options = new ChatOptions
{
Tools = [ocrTool],
};
var response = await chatClient.GetResponseAsync(
"Extract all text from this document image: https://example.com/document.jpg",
options);
|
Use AsInstanceSegmentationTool() to run pixel-level instance segmentation:
| var segmentationTool = roboflowClient.AsInstanceSegmentationTool(confidence: 0.5);
var options = new ChatOptions
{
Tools = [segmentationTool],
};
|
All four tools can be used together to give an LLM comprehensive computer vision capabilities:
| var options = new ChatOptions
{
Tools =
[
roboflowClient.AsObjectDetectionTool(confidence: 0.5),
roboflowClient.AsClassificationTool(confidence: 0.5),
roboflowClient.AsOcrTool(),
roboflowClient.AsInstanceSegmentationTool(confidence: 0.5),
],
};
|
Cross-SDK tool combination
Roboflow vision tools can be combined with search tools from Tavily or Exa in a single ChatOptions.Tools list for multimodal research workflows.