Linq.AI.OpenAI
1.0.1
See the version list below for details.
dotnet add package Linq.AI.OpenAI --version 1.0.1
NuGet\Install-Package Linq.AI.OpenAI -Version 1.0.1
<PackageReference Include="Linq.AI.OpenAI" Version="1.0.1" />
paket add Linq.AI.OpenAI --version 1.0.1
#r "nuget: Linq.AI.OpenAI, 1.0.1"
// Install Linq.AI.OpenAI as a Cake Addin #addin nuget:?package=Linq.AI.OpenAI&version=1.0.1 // Install Linq.AI.OpenAI as a Cake Tool #tool nuget:?package=Linq.AI.OpenAI&version=1.0.1
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
These extensions all take a ChatClient() as parameter and use OpenAI API to resolve.
Extension | Description |
---|---|
.Where() | Filter the collection of items by using a LLM filter |
.Select() | transform the item into another format using a LLM |
.Remove() | Remove items from a collection of items by using a LLM filter |
.Summarize() | Create a summarization for each item by using a LLM |
.Classify() | classify each item using a LLM |
.Answer() | get the answer to a question for each item using a LLM |
Examples
.Classify( )
This allows you to classify each item using LLM.
enum Genres { Rock, Pop, Electronica, Country, Classical };
var classifiedItems = items.ClassifyAI<Genres>(chatClient)).ToList();
.Where()/.Remove()
This lets you filter a collection using natural language
var breadboxItems = items.Where(chatClient, "item would fit in a bread box")).ToList()
var bigItems = items.Remove(chatClient, "item would fit in a bread box")).ToList()
.Select()
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.Select(chatClient, "transform each item into markdown like this:\n# {{TITLE}}\n{{AUTHOR}}\n{{Description}}")
.Summarize()
Generate text summary for each object.
var summaries= items.Summarize(chatClient)
You can control the summarization with a hint
var summaries = items.Summarize(chatClient, "genreate a 3 paragraph summary");
.Answer()
This operator let's you ask a question for each item in a collection.
var answers = items.Answer(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)
.Summarize(chatClient)
.Answer(chatClient, "What is the population?")
.Select(answer => Convert.ToInt32(answer));
Product | Versions 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. |
-
net8.0
- Iciclecreek.Async (>= 1.0.3)
- Newtonsoft.Json (>= 13.0.3)
- OpenAI (>= 2.0.0-beta.11)
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 |