@unified-llm/core
Version:
Unified LLM interface (in-memory).
75 lines (74 loc) • 2.02 kB
TypeScript
/**
* ResponseFormat class for unified structured output interface
* Provides a consistent way to define structured output across different LLM providers
*/
export interface JsonSchema {
type: 'object' | 'array' | 'string' | 'number' | 'boolean' | 'null';
properties?: Record<string, JsonSchema>;
items?: JsonSchema;
required?: string[];
additionalProperties?: boolean;
description?: string;
enum?: any[];
[key: string]: any;
}
export interface ResponseFormatConfig {
name: string;
description?: string;
schema: JsonSchema;
strict?: boolean;
}
export declare class ResponseFormat {
private config;
constructor(config: ResponseFormatConfig);
/**
* Convert to OpenAI's response_format structure
*/
toOpenAI(): any;
/**
* Convert to Google's responseSchema structure
*/
toGoogle(): any;
/**
* Convert to Anthropic's format using prompt engineering
*/
toAnthropic(): any;
/**
* Get the raw unified format
*/
toUnified(): any;
/**
* Add response format instruction to messages (for Anthropic)
*/
addRequestSuffix(messages: any[]): any[];
/**
* Convert JSON Schema to Google's Schema format
*/
private convertToGoogleSchema;
private mapToGoogleType;
/**
* Ensure all object schemas have additionalProperties: false for OpenAI compatibility
*/
private ensureAdditionalPropertiesFalse;
}
/**
* Helper function to create a ResponseFormat instance
*/
export declare function createResponseFormat(config: ResponseFormatConfig): ResponseFormat;
/**
* Pre-defined response format templates
*/
export declare const ResponseFormats: {
/**
* Simple key-value pair response
*/
keyValue: (keys: string[]) => ResponseFormat;
/**
* List of items
*/
list: (itemSchema: JsonSchema) => ResponseFormat;
/**
* Classification response
*/
classification: (categories: string[]) => ResponseFormat;
};