UNPKG

@jackhua/mini-langchain

Version:

A lightweight TypeScript implementation of LangChain with cost optimization features

97 lines 2.64 kB
import { PromptTemplate as IPromptTemplate } from '../core/types'; /** * A prompt template for a language model. * * A prompt template consists of a string template with variables that can be formatted. * * Example: * ```typescript * const template = new PromptTemplate({ * template: "Tell me a {adjective} joke about {topic}", * inputVariables: ["adjective", "topic"] * }); * * const prompt = template.format({ * adjective: "funny", * topic: "chickens" * }); * // Result: "Tell me a funny joke about chickens" * ``` */ export declare class PromptTemplate implements IPromptTemplate { template: string; inputVariables: string[]; partialVariables: Record<string, any>; constructor(config: { template: string; inputVariables: string[]; partialVariables?: Record<string, any>; skipValidation?: boolean; }); /** * Validate that all variables in the template are accounted for */ private validateTemplate; /** * Extract variables from a template string */ private extractVariables; /** * Format the prompt with the given values */ format(values: Record<string, any>): string; /** * Partial format - create a new template with some variables already filled */ partial(values: Record<string, any>): PromptTemplate; /** * Create a prompt template from a string with automatic variable detection */ static fromTemplate(template: string): PromptTemplate; } /** * A chat prompt template for conversations */ export interface ChatPromptValue { messages: Array<{ role: string; content: string; }>; } export declare class ChatPromptTemplate { private messages; constructor(messages: Array<[string, string | PromptTemplate]>); /** * Format the chat prompt with the given values */ format(values: Record<string, any>): ChatPromptValue; /** * Create a chat prompt template from messages */ static fromMessages(messages: Array<[string, string]>): ChatPromptTemplate; } /** * Common prompt templates */ export declare class PromptTemplates { /** * A simple question-answering prompt */ static QA: PromptTemplate; /** * A summarization prompt */ static SUMMARIZE: PromptTemplate; /** * A chat conversation prompt */ static CHAT: ChatPromptTemplate; /** * A few-shot learning prompt */ static fewShot(examples: Array<{ input: string; output: string; }>, suffix: string): PromptTemplate; } //# sourceMappingURL=prompt.d.ts.map