ai-utils.js
Version:
Build AI applications, chatbots, and agents with JavaScript and TypeScript.
20 lines (19 loc) • 849 B
TypeScript
import { TextGenerationModel } from "model-function/generate-text/TextGenerationModel.js";
import { ChatPrompt } from "./ChatPrompt.js";
/**
* Keeps only the most recent messages in the prompt, while leaving enough space for the completion.
*
* It will remove user-ai message pairs that don't fit. The result is always a valid chat prompt.
*
* When the minimal chat prompt (system message + last user message) is already too long, it will only
* return this minimal chat prompt.
*/
export declare function trimChatPrompt({ prompt, model, tokenLimit, }: {
prompt: ChatPrompt;
model: TextGenerationModel<ChatPrompt, any, any, any> & {
contextWindowSize: number;
maxCompletionTokens: number;
countPromptTokens: (prompt: ChatPrompt) => PromiseLike<number>;
};
tokenLimit?: number;
}): Promise<ChatPrompt>;