jorel
Version:
A unified wrapper for working with LLMs from multiple providers, including streams, images, documents & automatic tool use.
61 lines (60 loc) • 2.24 kB
TypeScript
export type CreateLlmDocument = Pick<LlmDocument, "title" | "content"> & Partial<LlmDocument> & {
attributes?: Record<string, string | number | boolean | null>;
};
export interface LlmDocumentDefinition {
id: string;
type: string;
title: string;
content: string;
source?: string;
attributes?: Record<string, string | number | boolean | null>;
}
/**
* A document that can be used for grounding LLM generations (either directly or passed to agents)
*/
export declare class LlmDocument {
id: string;
type: string;
title: string;
content: string;
source?: string;
attributes?: Record<string, string | number | boolean | null>;
constructor({ id, type, title, content, source, attributes }: CreateLlmDocument);
/**
* Get the definition of the document (e.g. for serialization)
*/
get definition(): LlmDocumentDefinition;
/**
* Write the document content to a local file
* @param path
*/
writeContentToLocalFile(path: string): Promise<void>;
/**
* @deprecated Use `fromFile` instead
*/
static fromLocalFile(path: string, meta?: Partial<Pick<LlmDocument, "type" | "title" | "id">>): Promise<LlmDocument>;
/**
* Create a new document from a local file
*/
static fromFile(path: string, meta?: Partial<Pick<LlmDocument, "type" | "title" | "id">>): Promise<LlmDocument>;
/**
* Create a list of documents from local files
*/
static fromFiles(paths: string[], meta?: Partial<Pick<LlmDocument, "type" | "title">>): Promise<LlmDocument[]>;
/**
* Create a new document from a URL
*/
static fromUrl(url: string, meta?: Partial<Pick<LlmDocument, "type" | "title" | "id">>): Promise<LlmDocument>;
/**
* Create a list of documents from URLs
*/
static fromUrls(urls: string[], meta?: Partial<Pick<LlmDocument, "type" | "title">>): Promise<LlmDocument[]>;
/**
* Create a new markdown document
*/
static md(payload: Pick<LlmDocument, "id" | "title" | "content"> & Partial<LlmDocument>): LlmDocument;
/**
* Create a new text document
*/
static text(payload: Pick<LlmDocument, "id" | "title" | "content"> & Partial<LlmDocument>): LlmDocument;
}