![]() |
VOOZH | about |
dotnet add package Devlooped.Extensions.AI --version 2.0.3
NuGet\Install-Package Devlooped.Extensions.AI -Version 2.0.3
<PackageReference Include="Devlooped.Extensions.AI" Version="2.0.3" />
<PackageVersion Include="Devlooped.Extensions.AI" Version="2.0.3" />Directory.Packages.props
<PackageReference Include="Devlooped.Extensions.AI" />Project file
paket add Devlooped.Extensions.AI --version 2.0.3
#r "nuget: Devlooped.Extensions.AI, 2.0.3"
#:package Devlooped.Extensions.AI@2.0.3
#addin nuget:?package=Devlooped.Extensions.AI&version=2.0.3Install as a Cake Addin
#tool nuget:?package=Devlooped.Extensions.AI&version=2.0.3Install as a Cake Tool
Extensions for Microsoft.Extensions.AI
Since tweaking chat options such as model identifier, reasoning effort, verbosity and other model settings is very common, this package provides the ability to drive those settings from configuration (with auto-reload support), both per-client as well as per-request. This makes local development and testing much easier and boosts the dev loop:
{
"AI": {
"Clients": {
"Grok": {
"Endpoint": "https://api.x.ai/v1",
"ModelId": "grok-4-1-fast-non-reasoning",
"ApiKey": "xai-asdf"
}
}
}
}
var host = new HostApplicationBuilder(args);
host.Configuration.AddJsonFile("appsettings.json, optional: false, reloadOnChange: true);
host.AddChatClients();
var app = host.Build();
var grok = app.Services.GetRequiredKeyedService<IChatClient>("Grok");
Changing the appsettings.json file will automatically update the client
configuration without restarting the application.
There's also a simpler Chat class for streamlined creation of chat messages, which can
be used instead of creating an array of ChatMessage using ChatRole.[System|Assistant|User]:
var messages = new Chat()
{
{ "system", "You are a highly intelligent AI assistant." },
{ "user", "What is 101*3?" },
};
Given the following tool:
MyResult RunTool(string name, string description, string content) { ... }
You can use the ToolFactory and FindCall<MyResult> extension method to
locate the function invocation, its outcome and the typed result for inspection:
AIFunction tool = ToolFactory.Create(RunTool);
var options = new ChatOptions
{
ToolMode = ChatToolMode.RequireSpecific(tool.Name), // 👈 forces the tool to be used
Tools = [tool]
};
var response = await client.GetResponseAsync(chat, options);
// 👇 finds the expected result of the tool call
var result = response.FindCalls<MyResult>(tool).FirstOrDefault();
if (result != null)
{
// Successful tool call
Console.WriteLine($"Args: '{result.Call.Arguments.Count}'");
MyResult typed = result.Result;
}
else
{
Console.WriteLine("Tool call not found in response.");
}
If the typed result is not found, you can also inspect the raw outcomes by finding
untyped calls to the tool and checking their Outcome.Exception property:
var result = response.FindCalls(tool).FirstOrDefault();
if (result.Outcome.Exception is not null)
{
Console.WriteLine($"Tool call failed: {result.Outcome.Exception.Message}");
}
else
{
Console.WriteLine($"Tool call succeeded: {result.Outcome.Result}");
}
The ToolFactory will also automatically sanitize the tool name
when using local functions to avoid invalid characters and honor
its original name.
OpenAI-specific extensions enable more seamless usage with the MS.E.AI API:
These can be used as extension properties on ChatOptions whenever Devlooped.Extensions.AI.OpenAI is imported:
var options = new ChatOptions
{
Verbosity = Verbosity.Low // 👈 or Medium/High, extension property
};
var response = await chat.GetResponseAsync(messages, options);
Or you can opt to use the ChatOptions-derived OpenAIChatOptions class directly.
The WebSearchTool can be used to customize the web search behavior in a typed manner,
unlike the generic HostedWebSearchTool:
var options = new ChatOptions
{
// 👇 search in Argentina, Bariloche region
Tools = [new WebSearchTool("AR")
{
AllowedDomains = ["catedralaltapatagonia.com"], // 👈 restrict domain
Region = "Bariloche", // 👈 Bariloche region
TimeZone = "America/Argentina/Buenos_Aires", // 👈 IANA timezone
}]
};
This enables all features supported by the Web search feature in OpenAI.
If advanced search settings are not needed, you can use the built-in M.E.AI HostedWebSearchTool
instead, which is a more generic tool and provides the basics out of the box.
The underlying HTTP pipeline provided by the Azure SDK allows setting up policies that can observe requests and responses. This is useful for monitoring the requests and responses sent to the AI service, regardless of the chat pipeline configuration used.
This is added to the OpenAIClientOptions (or more properly, any
ClientPipelineOptions-derived options) using the Observe method:
var openai = new OpenAIClient(
Environment.GetEnvironmentVariable("OPENAI_API_KEY")!,
new OpenAIClientOptions().Observe(
onRequest: request => Console.WriteLine($"Request: {request}"),
onResponse: response => Console.WriteLine($"Response: {response}"),
));
You can for example trivially collect both requests and responses for payload analysis in tests as follows:
var requests = new List<JsonNode>();
var responses = new List<JsonNode>();
var openai = new OpenAIClient(
Environment.GetEnvironmentVariable("OPENAI_API_KEY")!,
new OpenAIClientOptions().Observe(requests.Add, responses.Add));
We also provide a shorthand factory method that creates the options and observes is in a single call:
var requests = new List<JsonNode>();
var responses = new List<JsonNode>();
var openai = new OpenAIClient(
Environment.GetEnvironmentVariable("OPENAI_API_KEY")!,
OpenAIClientOptions.Observable(requests.Add, responses.Add));
To ensure the long-term sustainability of this project, users of this package who generate revenue must pay an Open Source Maintenance Fee. While the source code is freely available under the terms of the License, this package and other aspects of the project require adherence to the Maintenance Fee.
To pay the Maintenance Fee, become a Sponsor at the proper OSMF tier. A single fee covers all of Devlooped packages.
👁 Clarius Org
👁 MFB Technologies, Inc.
👁 SandRock
👁 DRIVE.NET, Inc.
👁 Keith Pickford
👁 Thomas Bolon
👁 Kori Francis
👁 Uno Platform
👁 Reuben Swartz
👁 Jacob Foshee
👁 alternate text is missing from this package README image
👁 Eric Johnson
👁 Jonathan
👁 Ken Bonny
👁 Simon Cropp
👁 agileworks-eu
👁 Zheyu Shen
👁 Vezel
👁 ChilliCream
👁 4OTC
👁 domischell
👁 Adrian Alonso
👁 Michael Hagedorn
👁 torutek
👁 mccaffers
👁 Seika Logiciel
👁 Andrew Grant
👁 Lars
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 3 NuGet packages that depend on Devlooped.Extensions.AI:
| Package | Downloads |
|---|---|
|
Smith
Run AI-powered C# files using Microsoft.Extensions.AI and Devlooped.Extensions.AI |
|
|
Devlooped.Agents.AI
Extensions for Microsoft.Agents.AI |
|
|
Devlooped.Extensions.AI.Console
Console logging extensions for Devlooped.Extensions.AI |
This package is not used by any popular GitHub repositories.