services/ask library
Answers a question from on-device search with a generation function the app supplies, without depending on any LLM SDK.
Classes
- RagAnswer
-
An answer from
ask, with the passages it was based on. - RagAskPrompt
-
The prompt for one question, built by
prepareAsk. - RagPassage
- A passage given to the LLM, with the citation id the model uses.
Functions
-
askWith(
RagSearchTool tool, String question, {required RagGenerate generate, RagPromptBuilder buildPrompt = defaultAskPrompt}) → Future< RagAnswer> -
prepareAskWith, then
generate, then RagAskPrompt.answer.generateis not called when no passages were found. -
citedPassages(
String text, List< RagPassage> passages) → List<RagPassage> -
Passages of
passagescited intextas[1],[1, 2]or[1][2], in order of first citation and without repeats. -
defaultAskPrompt(
String question, List< RagPassage> passages) → String - Default prompt: instructions, numbered passages, then the question.
-
prepareAskWith(
RagSearchTool tool, String question, {RagPromptBuilder buildPrompt = defaultAskPrompt}) → Future< RagAskPrompt> -
Searches with
tool(itsdefaultTopKpassages) and builds the prompt forquestion.
Typedefs
-
RagGenerate
= Future<
String> Function(String prompt) -
Generates the answer for
promptwith the app's LLM. -
RagPromptBuilder
= String Function(String question, List<
RagPassage> passages) -
Builds the prompt sent to the LLM from the
questionand thepassagesfound for it.