ALwrity HALLUCINATION DETECTOR AND ASSISTIVE WRITING

This commit is contained in:
ajaysi
2025-09-08 21:14:27 +05:30
parent 5ba19c097a
commit 6fd9a4e354
51 changed files with 8224 additions and 1086 deletions

View File

@@ -13,12 +13,6 @@ export function formatDraftContent(content: string, citations?: any[], researchS
// Insert inline citations if available
if (citations && citations.length > 0 && researchSources && researchSources.length > 0) {
console.log('🔍 [formatDraftContent] Processing citations:', {
citationsCount: citations.length,
researchSourcesCount: researchSources.length,
citations: citations,
contentLength: content.length
});
// Create a map of citation references to source numbers
const citationMap = new Map();
@@ -28,8 +22,6 @@ export function formatDraftContent(content: string, citations?: any[], researchS
citationMap.set(citation.reference, sourceNum);
}
});
console.log('🔍 [formatDraftContent] Citation map created:', citationMap);
// Since citation references don't exist in the content text,
// we need to insert citations strategically throughout the content
@@ -51,26 +43,13 @@ export function formatDraftContent(content: string, citations?: any[], researchS
const sentenceWithCitation = targetSentence.trim() + citeHtml;
sentencesWithCitations[targetSentenceIndex] = sentenceWithCitation;
console.log(`✅ [formatDraftContent] Added citation [${sourceNum}] to sentence ${targetSentenceIndex + 1}`);
});
// Reconstruct content with citations
formatted = sentences.map((sentence, index) => {
return sentencesWithCitations[index] || sentence;
}).join('. ') + '.';
console.log(`✅ [formatDraftContent] Inserted ${totalCitations} citations strategically throughout content`);
// Debug: Show sample of content with citations
const sampleContent = formatted.substring(0, 500) + (formatted.length > 500 ? '...' : '');
console.log('🔍 [formatDraftContent] Sample content with citations:', sampleContent);
// Debug: Count citation markers in final content
const citationMarkers = (formatted.match(/\[\d+\]/g) || []).length;
console.log(`🔍 [formatDraftContent] Found ${citationMarkers} citation markers in final content`);
}
console.log('🔍 [formatDraftContent] Final formatted content length:', formatted.length);
}
// Format hashtags

View File

@@ -5,6 +5,9 @@
import { useCopilotContext } from '@copilotkit/react-core';
// Optional debug flag: set to true to enable verbose logs locally
const DEBUG_PERSISTENCE = false;
// Storage keys for different types of data
export const STORAGE_KEYS = {
CHAT_HISTORY: 'alwrity-copilot-chat-history',
@@ -198,7 +201,7 @@ export class CopilotPersistenceManager {
public saveDraftContent(draft: string): void {
try {
localStorage.setItem(STORAGE_KEYS.DRAFT_CONTENT, draft);
console.log('💾 Saved draft content');
if (DEBUG_PERSISTENCE) console.log('💾 Saved draft content');
} catch (error) {
console.error('❌ Failed to save draft content:', error);
}