langextract
Version:
A TypeScript library for extracting structured and grounded information from text using LLMs
84 lines • 2.82 kB
TypeScript
/**
* Copyright 2025 kmbro.
*
* This is a TypeScript translation of the original Python LangExtract library
* by Google LLC (https://github.com/google/langextract).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ScoredOutput, FormatType } from "./types";
import { GeminiSchema } from "./schema";
export declare class InferenceOutputError extends Error {
constructor(message: string);
}
export interface BaseLanguageModel {
infer(batchPrompts: string[], options?: InferenceOptions): Promise<ScoredOutput[][]>;
}
export interface InferenceOptions {
temperature?: number;
maxDecodeSteps?: number;
[key: string]: any;
}
export interface GeminiConfig {
modelId: string;
apiKey: string;
geminiSchema?: GeminiSchema;
formatType: FormatType;
temperature: number;
maxWorkers: number;
modelUrl?: string;
maxTokens?: number;
}
export interface OpenAIConfig {
model: string;
apiKey: string;
openAISchema?: GeminiSchema;
formatType: FormatType;
temperature: number;
maxWorkers: number;
baseURL?: string;
maxTokens?: number;
}
export declare class GeminiLanguageModel implements BaseLanguageModel {
private config;
private constraint;
constructor(config?: Partial<GeminiConfig>);
infer(batchPrompts: string[], options?: InferenceOptions): Promise<ScoredOutput[][]>;
private processSinglePrompt;
private callGeminiAPI;
parseOutput(output: string): any;
}
export declare class OpenAILanguageModel implements BaseLanguageModel {
private config;
private constraint;
constructor(config?: Partial<OpenAIConfig>);
infer(batchPrompts: string[], options?: InferenceOptions): Promise<ScoredOutput[][]>;
private processSinglePrompt;
private callOpenAIAPI;
parseOutput(output: string): any;
}
export interface OllamaConfig {
model: string;
modelUrl: string;
structuredOutputFormat: string;
temperature: number;
maxTokens?: number;
}
export declare class OllamaLanguageModel implements BaseLanguageModel {
private config;
private constraint;
constructor(config?: Partial<OllamaConfig>);
infer(batchPrompts: string[], options?: InferenceOptions): Promise<ScoredOutput[][]>;
private ollamaQuery;
}
//# sourceMappingURL=inference.d.ts.map