@anuran-roy/langtache
Version:
Mustache-driven chat prompt helpers
29 lines (25 loc) • 1.22 kB
TypeScript
import OpenAI from 'openai';
import { z } from 'zod';
declare class ChatPromptTemplate {
protected template: string;
protected llm: OpenAI | null;
protected variables: string[] | null;
protected invokeFn: (...params: any) => string;
constructor(params: {
template: string;
inputVariables: string[];
templateFormat?: "mustache";
});
static fromTemplate(template: string): ChatPromptTemplate;
pipe(llm: OpenAI): this;
pipe(invokeFn: (...args: any[]) => string): this;
format(params: Record<string, any>): string;
invoke(model: string, params: Record<string, any>): Promise<OpenAI.Chat.Completions.ChatCompletion & {
_request_id?: string | null;
}>;
}
declare function getStructuredOutput<T extends z.ZodTypeAny>(schema: T): (data: any) => string;
declare function getValidatedOutput<T extends z.ZodTypeAny>(schema: T, data: string): z.ZodSafeParseResult<z.core.output<T>>;
declare function isObjectorArray(value: any): value is Record<string, any> | Array<any>;
declare function parseUntilJson(jsonstr: string): Record<string, any>;
export { ChatPromptTemplate, getStructuredOutput, getValidatedOutput, isObjectorArray, parseUntilJson };