aiwrapper
Version:
A Universal AI Wrapper for JavaScript & TypeScript
68 lines (67 loc) • 2.21 kB
TypeScript
import { z } from 'zod';
import { LangMessages } from "./messages.ts";
import type { LangMessage, LangMessageItem, LangMessageRole } from "./messages.ts";
export { z };
/**
* Type for any supported schema (Zod or JSON Schema)
*/
export type LangResponseSchema = z.ZodType | Record<string, unknown>;
export type { LangMessage, LangContentPart, LangContentImage as LangImageInput } from "./messages.ts";
/**
* Image output type for providers that can generate images
*/
export type LangImageOutput = {
url?: string;
base64?: string;
mimeType?: string;
width?: number;
height?: number;
provider?: string;
model?: string;
metadata?: Record<string, unknown>;
};
/**
* Options that can be passed to language model methods
*/
export interface LangOptions {
schema?: LangResponseSchema;
onResult?: (result: LangMessage) => void;
signal?: AbortSignal;
providerSpecificBody?: Record<string, any>;
providerSpecificHeaders?: Record<string, string>;
}
/**
* Backward-compatible result class that is also the conversation object
* Extends LangMessages and exposes a 'messages' getter for old code.
*/
export declare class LangResult extends LangMessages {
constructor(messages: LangMessages | LangMessage[]);
get messages(): this;
}
/**
* LanguageProvider is an abstract class that represents a language model and
* its basic functionality.
*/
export declare abstract class LanguageProvider {
readonly name: string;
constructor(name: string);
/**
* Simple text generation
*/
abstract ask(prompt: string, options?: LangOptions): Promise<LangMessages>;
/**
* Continue a conversation
*/
abstract chat(messages: {
role: LangMessageRole;
items: LangMessageItem[];
}[] | LangMessage[] | LangMessages, options?: LangOptions): Promise<LangMessages>;
/**
* Get structured answer from a language model
* Supports both Zod schemas and JSON Schema objects
*/
askForObject(prompt: string | {
role: LangMessageRole;
items: LangMessageItem[];
}[] | LangMessage[] | LangMessages, schema: LangResponseSchema, options?: LangOptions): Promise<LangMessages>;
}