UNPKG

@solvers-hub/llm-json

Version:

A TypeScript SDK to extract and correct JSON from LLM outputs

38 lines (37 loc) 1.46 kB
import { ExtractOptions, ExtractResult, JsonBlock } from './types'; import { JsonExtractor } from './extractor'; /** * Specialized extractor for handling JSON arrays in text. */ export declare class JsonArrayExtractor extends JsonExtractor { /** * Creates a new instance of JsonArrayExtractor. * @param options - Configuration options for extraction. */ constructor(options?: ExtractOptions); /** * Find potential JSON array blocks in the input string. * @param input - The input string to search for JSON arrays. * @returns Array of detected JSON blocks containing arrays. */ protected findJsonArrayBlocks(input: string): JsonBlock[]; /** * Determines if a potential array block is inside a JSON object. * @param arrayBlock - The array block to check. * @param objectBlocks - Array of object blocks to check against. * @returns True if the array is inside an object, false otherwise. */ private isArrayInsideObject; /** * Clean up text blocks to match the expected format. * @param blocks - The text blocks to clean. * @returns Cleaned text blocks. */ private cleanTextBlocks; /** * Extract JSON arrays and text from a string input. * @param input - The input string that may contain JSON arrays. * @returns An object containing arrays of extracted text and JSON. */ extractArrays(input: string): ExtractResult; }