DimonSmart.AiUtils 1.25110.2049

Prefix Reserved
dotnet add package DimonSmart.AiUtils --version 1.25110.2049                
NuGet\Install-Package DimonSmart.AiUtils -Version 1.25110.2049                
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="DimonSmart.AiUtils" Version="1.25110.2049" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DimonSmart.AiUtils --version 1.25110.2049                
#r "nuget: DimonSmart.AiUtils, 1.25110.2049"                
#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 DimonSmart.AiUtils as a Cake Addin
#addin nuget:?package=DimonSmart.AiUtils&version=1.25110.2049

// Install DimonSmart.AiUtils as a Cake Tool
#tool nuget:?package=DimonSmart.AiUtils&version=1.25110.2049                

DimonSmart.AiUtils

DimonSmart.AiUtils is a library designed to extract JSON strings from responses generated by Large Language Models (LLMs). It ensures accurate extraction even when the LLM response contains additional text, including explanations or phrases such as "Here is your JSON."

Background

LLMs often produce additional text alongside the requested JSON data. This can include explanations, clarifications, or contextual information that may interfere with JSON parsing. DimonSmart.AiUtils addresses this issue by extracting only the valid JSON strings from the response, allowing for seamless integration with JSON parsers.

Features

  • ExtractJson: Returns the largest valid JSON object or array as a string from the provided text.
  • ExtractAllJsons: Returns all valid JSON objects or arrays as strings from the text.
  • ExtractJson (overload): Returns a single JSON fragment as a string, starting from a specific index in the text.

API Overview

ExtractJson(string? text)

Extracts and returns the largest valid JSON object or array as a string from the input text.

string json = JsonExtractor.ExtractJson(responseText);

ExtractAllJsons(string? text)

Extracts all valid JSON objects or arrays from the input text.

var jsons = JsonExtractor.ExtractAllJsons(responseText);

ExtractJson(int start, string? text)

Extracts a single valid JSON fragment starting from the specified index in the text.

string json = JsonExtractor.ExtractJson(0, responseText);

Installation

Install via NuGet:

dotnet add package DimonSmart.AiUtils

Use Cases

  • Preprocess LLM responses to extract structured JSON data.
  • Handle mixed LLM responses that include additional text explanations or metadata.
  • Extract multiple JSON fragments from a single response.
  • Clean up LLM outputs to obtain pure JSON strings for parsing.

License

This library is licensed under the 0BSD License.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

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
1.25110.2049 77 1/10/2025