formatForPrompt static method
String
formatForPrompt({
- required String query,
- required AssembledContext context,
- String? systemInstruction,
- bool useStrictMode = true,
Format context for LLM prompt.
Creates a prompt that instructs the LLM to answer based ONLY on the provided documents. Uses bilingual instructions for better compliance with smaller models.
Implementation
static String formatForPrompt({
required String query,
required AssembledContext context,
String? systemInstruction,
bool useStrictMode =
true, // Strict mode instructs LLM to ONLY use documents
}) {
if (context.text.isEmpty) {
return query;
}
// Default instruction: bilingual for better model understanding
final instruction =
systemInstruction ??
(useStrictMode
? 'Answer the question based ONLY on the documents below. If the information is not in the documents, say "I could not find the information in the provided documents".'
: 'Answer based on the following documents:');
return '''$instruction
--- Reference Documents ---
${context.text}
--- End of Documents ---
Question: $query
Answer:''';
}