Linq.AI.OpenAI 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Linq.AI.OpenAI --version 1.0.0                
NuGet\Install-Package Linq.AI.OpenAI -Version 1.0.0                
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="Linq.AI.OpenAI" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Linq.AI.OpenAI --version 1.0.0                
#r "nuget: Linq.AI.OpenAI, 1.0.0"                
#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.
// Install Linq.AI.OpenAI as a Cake Addin
#addin nuget:?package=Linq.AI.OpenAI&version=1.0.0

// Install Linq.AI.OpenAI as a Cake Tool
#tool nuget:?package=Linq.AI.OpenAI&version=1.0.0                

Linq.AI.OpenAI

This library adds Linq extension methods using OpenAI structured outputs. (heaviy inspired by stevenic's agentm-js library)

Architecture

For each element in a collection an openAI API call is made to evaluate and return the result. These are done in parallel on background threads.

ChatClient

To use this you will need to instantiate a ChatClient like this:

new ChatClient(model: "gpt-4o-2024-08-06", "<OpenAIKey>");

Extensions

Extension Description
.WhereAI() Filter the collection of items by using a LLM filter
.SelectAI() transform the item into another format using a LLM
.RemoveAI() Remove items from a collection of items by using a LLM filter
.SummarizeAI() Create a summarization for each item by using a LLM
.ClassifyAI() classify each item using a LLM
.AnswerAI() get the answer to a question for each item using a LLM

Examples

.ClassifyAI( )

This allows you to classify each item using LLM.

enum Genres { Rock, Pop, Electronica, Country, Classical };
var classifiedItems = items.ClassifyAI<Genres>(chatClient)).ToList();

.WhereAI()/.RemoveAI()

This lets you filter a collection using natural language

var breadboxItems = items.WhereAI(chatClient, "item would fit in a bread box")).ToList()
var bigItems = items.RemoveAI(chatClient, "item would fit in a bread box")).ToList()

.SelectAI()

This lets you transform the source into another structure using natural language.

Object transformation

You can use it to transform an object from one format to another by simply giving the types. It will use LLM to do the transformation.

var targetItems = items.SelectAI<SourceItem,TargetItem>(chatClient"))

String transformation

var markdownItems = items.SelectAI(chatClient, "transform each item into markdown like this:\n# {{TITLE}}\n{{AUTHOR}}\n{{Description}}")

.SummarizeAI()

Generate text summary for each object.

var summaries= items.SummarizeAI(chatClient)

You can control the summarization with a hint

var summaries = items.SummarizeAI(chatClient, "genreate a 3 paragraph summary");

.AnswerAI()

This operator let's you ask a question for each item in a collection.

var answers = items.AnswerAI(chatClient, "What is total cost of the item as a float?").Select(answer => Convert.ToFloat(answer));

Chaining operations

Linq.AI operations and normal linq operations can be mixed together.

var populations = items.SelectAI<SourceT, TargetT>(chatClient)
	.SummarizeAI(chatClient)
	.AnswerAI(chatClient, "What is the population?")
	.Select(answer => Convert.ToInt32(answer));
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. 
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
2.2.1 48 12/16/2024
2.2.0 68 10/15/2024
2.1.0 60 10/11/2024
2.0.6 96 9/15/2024
2.0.5 72 9/14/2024
2.0.4 87 9/14/2024
2.0.3 60 9/14/2024
2.0.2 62 9/14/2024
2.0.1 73 9/14/2024
1.3.0 65 9/14/2024
1.2.3 64 9/13/2024
1.2.2 65 9/12/2024
1.2.1 74 9/12/2024
1.2.0 64 9/11/2024
1.1.0 66 9/11/2024
1.0.1 65 9/11/2024
1.0.0 66 9/11/2024