jorel
Version:
A unified wrapper for working with LLMs from multiple providers, including streams, images, documents & automatic tool use.
113 lines (112 loc) • 4.3 kB
TypeScript
import { LLmMessageImageDataUrlContent, LLmMessageImageUrlContent } from "../providers";
interface BufferImage {
type: "buffer";
buffer: Buffer;
mimeType: string;
}
interface Base64Image {
type: "base64";
data: string;
mimeType: string;
}
interface UrlImage {
type: "url";
url: string;
mimeType: string;
}
type ImageSource = BufferImage | Base64Image | UrlImage;
export type ImageMetadata = Record<string, number | string | boolean | null>;
/**
* Simplifies handling of images handed to JorEl. Instances of this class can be
* created from a variety of sources, and can be passed directly to JorEl.
*/
export declare class ImageContent {
readonly metadata?: ImageMetadata;
constructor(source: ImageSource, metadata?: ImageMetadata);
/**
* Instantiates an image from a data URL
* @param dataUrl - The data URL of the image
* @param metadata - Metadata to attach to the image
*/
static fromDataUrl(dataUrl: string, metadata?: ImageMetadata): ImageContent;
/**
* Instantiates an image from a URL.
*
* By default, the image is downloaded, since some LLMs (like Ollama
* and Anthropic) currently do not support URLs directly.
* @param url - The URL of the image
* @param mimeType - The MIME type of the image
* @param downloadMedia - Whether to download the image or not
* @param metadata - Metadata to attach to the image
*/
static fromUrl(url: string, mimeType: string, downloadMedia: false, metadata?: ImageMetadata): Promise<ImageContent>;
static fromUrl(url: string, mimeType?: string, downloadMedia?: true, metadata?: ImageMetadata): Promise<ImageContent>;
/**
* Instantiates an array of images from an array of URLs
* @param urls - Array of URLs
* @param metadata - Metadata to attach to the images
*/
static fromUrls(urls: string[], metadata?: ImageMetadata): Promise<ImageContent[]>;
/**
* Instantiates an image from an existing buffer
* @param buffer - Buffer containing the image data
* @param mimeType - (optional) MIME type of the image
* @param metadata - Metadata to attach to the image
* @throws Error - Error if the MIME type cannot be detected
*/
static fromBuffer(buffer: Buffer, mimeType?: string, metadata?: ImageMetadata): Promise<ImageContent>;
/**
* Instantiates an image from a file path
* @param filePath - Path to the image file
* @param mimeType - (optional) MIME type of the image
* @param metadata - Metadata to attach to the image
* @throws Error - Error if the file cannot be read
*/
static fromFile(filePath: string, mimeType?: string, metadata?: ImageMetadata): Promise<ImageContent>;
/**
* Instantiates an array of images from an array of file paths
* @param files - Array of file paths
* @param mimeType - (optional) MIME type of the images
* @param metadata - Metadata to attach to the images
*/
static fromFiles(files: string[], mimeType?: string, metadata?: ImageMetadata): Promise<ImageContent[]>;
/**
* Returns the image as a buffer
* @returns The image buffer and its MIME type
*/
toBuffer(): Promise<{
buffer: Buffer;
mimeType: string;
}>;
/**
* Returns the image as a Uint8Array
* @returns The image as a Uint8Array
*/
toUint8Array(): Promise<Uint8Array>;
/**
* Returns the image as a base64 string
* @returns The image data and its MIME type
*/
toBase64(): Promise<{
data: string;
mimeType: string;
}>;
/**
* Returns the image as a data URL
* @returns The image data URL
*/
toDataUrl(): Promise<string>;
/**
* Returns the image as a message content
* @param downloadUrls - Whether to download the image and return a data URL
* @returns The image as a message content
*/
toMessageContent(downloadUrls?: false): Promise<LLmMessageImageDataUrlContent | LLmMessageImageUrlContent>;
toMessageContent(downloadUrls: true): Promise<LLmMessageImageDataUrlContent>;
/**
* Returns a string representation of the ImageContent instance
* @returns A string describing the image source
*/
toString(): string;
}
export {};