promptLength method
Returns the prompt length (number of tokens) given the documents passed in.
This can be used by a caller to determine whether passing in a list of documents would exceed a certain prompt length. This useful when trying to ensure that the size of a prompt remains below a certain context limit.
docs
is the list of documents to combine.inputs
is a map of other inputs to use in the combination.
Returns null if the combine method doesn't depend on the prompt length. Otherwise, the length of the prompt in tokens.
Implementation
@override
Future<int?> promptLength(
final List<Document> docs, {
final InputValues inputs = const {},
}) {
final llmInputs = _getInputs(docs, inputs);
final prompt = llmChain.prompt.formatPrompt(llmInputs);
return llmChain.llm.countTokens(prompt);
}