Add comprehensive chatbot improvements: better LLM prompts, caching, confidence labels, smarter follow-ups
This commit is contained in:
+29
@@ -1062,6 +1062,22 @@ function buildSmartFollowUpPrompts(chunks: SearchChunk[], analysis: IntentAnalys
|
||||
.slice(0, 3)
|
||||
.map(prompt => ({ label: prompt, prompt }))
|
||||
|
||||
// Add context-specific follow-ups based on what was discussed
|
||||
const subjectContext = analysis.subject || extractIdentitySubject(analysis.rawQuery.toLowerCase())
|
||||
if (subjectContext && !analysis.rawQuery.toLowerCase().includes('apply')) {
|
||||
promptSuggestions.unshift({
|
||||
label: `How does this apply to my life?`,
|
||||
prompt: `Based on what you just said about ${subjectContext}, how should I apply this today?`
|
||||
})
|
||||
}
|
||||
|
||||
if (primaryVerse && analysis.type === 'identity') {
|
||||
promptSuggestions.unshift({
|
||||
label: `What's the historical context?`,
|
||||
prompt: `What was the historical and cultural context of ${formatVerseRef(primaryVerse)}?`
|
||||
})
|
||||
}
|
||||
|
||||
const detailedNotesReply = buildDetailedNotesReplyFromChunks(chunks)
|
||||
const canOfferDetailedNotes = hasMeaningfulExtraDetail(shortAnswer, detailedNotesReply)
|
||||
|
||||
@@ -1152,6 +1168,18 @@ function synthesizeSmartReply(scored: ScoredChunk[], analysis: IntentAnalysis, c
|
||||
}
|
||||
}
|
||||
|
||||
function addConfidenceLabel(response: ChatResponse, confidence: 'high' | 'medium' | 'low'): ChatResponse {
|
||||
const label = confidence === 'high'
|
||||
? '✓ High confidence'
|
||||
: confidence === 'medium'
|
||||
? '~ Medium confidence'
|
||||
: '? Low confidence'
|
||||
return {
|
||||
...response,
|
||||
text: `${response.text}\n\n[${label}]`
|
||||
}
|
||||
}
|
||||
|
||||
function buildNextChatContext(query: string, analysis: IntentAnalysis, scored: ScoredChunk[], previousContext: ChatContextState): ChatContextState {
|
||||
const topChunks = getTopDistinctChunks(scored, 3)
|
||||
if (topChunks.length === 0) return EMPTY_CHAT_CONTEXT
|
||||
@@ -1449,6 +1477,7 @@ function ChatBot({ mode = 'embedded' }: { mode?: 'embedded' | 'standalone' }) {
|
||||
if (confidence !== 'low') {
|
||||
shouldTryLlmRewrite = true
|
||||
chatContextRef.current = buildNextChatContext(contextualQuery, analysis, scored, activeContext)
|
||||
botReply = addConfidenceLabel(botReply, confidence)
|
||||
}
|
||||
} else {
|
||||
botReply = buildSmartFallbackReply(analyzeIntent(contextualQuery, activeContext), activeContext)
|
||||
|
||||
Reference in New Issue
Block a user