Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 202:
font-size: 13px;
line-height: 1.5;
max-height:
overflow-y: auto;
white-space: pre-wrap;
Line 358:
if (this.getCurrentApiKey()) {
// Enable verify button if we have API key and either claim+source OR just show it enabled
const hasClaimAndSource = this.activeClaim && this.activeSource;
this.buttons.verify.setDisabled(!hasClaimAndSource);
container.appendChild(this.buttons.verify.$element[0]);
container.appendChild(this.buttons.changeKey.$element[0]);
container.appendChild(this.buttons.removeKey.$element[0]);
// Debug logging
console.log('Button visibility update:', {
hasApiKey: !!this.getCurrentApiKey(),
activeClaim: !!this.activeClaim,
activeSource: !!this.activeSource,
buttonDisabled: !hasClaimAndSource
});
} else {
this.buttons.verify.setDisabled(true);
Line 433 ⟶ 443:
document.getElementById('verifier-claim-text').textContent = claim;
// Fetch source content (URL extraction)
this.updateStatus('
const
if (!
this.updateStatus('Could not
return;
}
// Update UI with source info
this.activeSource =
const sourceElement = document.getElementById('verifier-source-text');
//
const urlMatch = sourceInfo.match(/Source URL: (https?:\/\/[^\s\n]+)/);
if (urlMatch) {
sourceElement.innerHTML = `<strong>Source URL:</strong><br><a href="${urlMatch[1]}" target="_blank" style="word-break: break-all;">${urlMatch[1]}</a><br><br><em>Content will be fetched and analyzed by AI during verification.</em>`;
} else {
sourceElement.textContent = sourceInfo;
}
// Enable verify button now that we have both claim and source
this.updateButtonVisibility();
this.updateStatus('Ready to verify claim against source');
console.log('Reference click completed:', {
claim: this.activeClaim ? 'Set' : 'Missing',
source: this.activeSource ? 'Set' : 'Missing',
apiKey: this.getCurrentApiKey() ? 'Set' : 'Missing'
});
} catch (error) {
Line 457 ⟶ 480:
}
extractClaimText(refElement) {
// Get the paragraph or container
const container = refElement.closest('p, li, td, div, section');
return '';
}
// Get all text content from the
let fullText = '';
const walker = document.createTreeWalker(
container,
false
);
let textNode;
const textNodes = [];
while (textNode = walker.nextNode()) {
node: textNode,
offset: fullText.length
});
fullText
// Find the position of the reference in the full text
let refPosition = -1;
// Look for the reference pattern in the text
const refPattern = new RegExp('\\[\\s*' + refText.replace(/[\[\]]/g, '') + '\\s*\\]');
const
if (refMatch) {
refPosition = refMatch.index;
} else {
// Fallback: find any reference pattern before our element
const allRefs =
if (allRefs)
// Find the last
let searchPos = 0;
const index = fullText.indexOf(ref, searchPos);
if (index !== -1) {
lastRefIndex = index;
searchPos = index + ref.length;
}
}
refPosition = lastRefIndex;
}
}
if (refPosition === -1) {
refPosition = fullText.length;
}
// Extract text before the reference
const textBeforeRef = fullText.substring(0, refPosition).trim();
// Find the last complete sentence
const sentences = textBeforeRef.split(/([.!?]+\s+)/);
if (sentences.length === 1) {
// No sentence breaks found, return the entire text
return textBeforeRef;
}
// Reconstruct the last sentence
let lastSentence = '';
let foundSentenceEnd = false;
// Work backwards through the sentence fragments
for (let i = sentences.length - 1; i >= 0; i--) {
const fragment = sentences[i];
if (fragment.match(/^[.!?]+\s*$/)) {
// This is punctuation + whitespace
if (!foundSentenceEnd) {
foundSentenceEnd = true;
continue;
} else {
// We've found the end of the previous sentence
break;
}
} else {
// This is text content
lastSentence = fragment + lastSentence;
if (foundSentenceEnd) {
// We have a complete sentence
break;
}
}
}
// If we didn't find a proper sentence boundary, fall back to a more aggressive approach
if (!lastSentence.trim() || lastSentence.trim().length < 10) {
// Look for other potential sentence boundaries
const alternativeBreaks = textBeforeRef.split(/([.!?:;]\s+|^\s*[A-Z])/);
if (alternativeBreaks.length > 1) {
lastSentence = alternativeBreaks[alternativeBreaks.length - 1];
} else {
// As a last resort, take a reasonable chunk from the end
const words = textBeforeRef.split(/\s+/);
if (words.length > 15) {
lastSentence = words.slice(-15).join(' ');
} else {
lastSentence = textBeforeRef;
}
}
}
// Clean up the result
lastSentence = lastSentence.trim();
// Ensure it ends with proper punctuation for context
if (lastSentence && !lastSentence.match(/[.!?]$/)) {
// Check if the original text continues with punctuation
const nextChar = fullText.charAt(refPosition - lastSentence.length - 1);
if (nextChar.match(/[.!?]/)) {
lastSentence = nextChar + ' ' + lastSentence;
}
}
// Remove any remaining reference brackets that might have been included
lastSentence = lastSentence.replace(/\[\d+\]/g, '').trim();
return lastSentence;
}
extractReferenceUrl(refElement) {
Line 531 ⟶ 646:
async fetchSourceContent(url) {
// Instead of trying to fetch the content directly (which fails due to CORS),
// we'll use the AI API to fetch and analyze the content
try {
//
return `Source URL: ${url}\n\n[Content will be fetched by AI during verification]`;
} catch (error) {
console.error('Error
throw new Error(`
}
}
Line 744 ⟶ 820:
this.updateButtonVisibility();
this.updateStatus('API key set successfully!');
// If we already have claim and source, enable verify button
if (this.activeClaim && this.activeSource) {
console.log('API key set - enabling verification');
this.updateButtonVisibility();
}
}
}
Line 806 ⟶ 888:
}
async callClaudeAPI(claim,
// Extract URL from sourceInfo
const urlMatch = sourceInfo.match(/Source URL: (https?:\/\/[^\s\n]+)/);
const sourceUrl = urlMatch ? urlMatch[1] : null;
const requestBody = {
model: this.providers.claude.model,
max_tokens:
system: `You are a fact-checking assistant. Your task is to verify whether a claim from a Wikipedia article is supported by the
Instructions:
1. First, fetch and read the content from the provided URL
2. Analyze the claim and determine what specific facts it asserts
3. Search through the source content for information that supports or contradicts the claim
4. Provide a clear verdict: SUPPORTED, PARTIALLY SUPPORTED, NOT SUPPORTED, or UNCLEAR
5. Quote the specific sentences from the source that support your verdict
6. Explain any discrepancies or missing information
Be precise and objective in your analysis.`,
messages: [{
role: "user",
content:
`Please fetch the content from this URL and verify the claim against it.
Source URL: ${sourceUrl}` :
`Claim to verify: "${claim}"
Source content: "${sourceInfo}"`
}]
};
Line 848 ⟶ 941:
}
async callGeminiAPI(claim,
const API_URL = `https://generativelanguage.googleapis.com/v1beta/models/${this.providers.gemini.model}:generateContent?key=${this.getCurrentApiKey()}`;
// Extract URL from sourceInfo
const urlMatch = sourceInfo.match(/Source URL: (https?:\/\/[^\s\n]+)/);
const sourceUrl = urlMatch ? urlMatch[1] : null;
const systemPrompt = `You are a fact-checking assistant. Verify whether a Wikipedia claim is supported by the source content at the provided URL.
Instructions:
1. Fetch and read the content from the provided URL
2. Analyze the claim and determine what specific facts it asserts
3. Search through the source content for information that supports or contradicts the claim
4. Provide a clear verdict: SUPPORTED, PARTIALLY SUPPORTED, NOT SUPPORTED, or UNCLEAR
5. Quote the specific sentences from the source that support your verdict
6. Explain any discrepancies or missing information
Be precise and objective in your analysis.`;
Line 862 ⟶ 962:
const requestBody = {
contents: [{
parts: [{ "text":
`Please fetch the content from this URL and verify the claim against it.
Claim to verify: "${claim}"
Source URL: ${sourceUrl}` :
`Claim to verify: "${claim}"
Source content: "${sourceInfo}"` }],
}],
systemInstruction: {
Line 871 ⟶ 979:
temperature: 0.0,
},
tools: [
{urlContext: {}},
{googleSearch: {}},
],
};
Line 897 ⟶ 1,009:
}
async callOpenAIAPI(claim,
// Extract URL from sourceInfo
const urlMatch = sourceInfo.match(/Source URL: (https?:\/\/[^\s\n]+)/);
const sourceUrl = urlMatch ? urlMatch[1] : null;
const requestBody = {
model: this.providers.openai.model,
Line 904 ⟶ 1,020:
{
role: "system",
content: `You are a fact-checking assistant. Your task is to verify whether a claim from a Wikipedia article is supported by the
Instructions:
1. Analyze the claim and determine what specific facts it asserts
2.
3. Provide a clear verdict: SUPPORTED, PARTIALLY SUPPORTED, NOT SUPPORTED, or UNCLEAR
4. Explain your reasoning based on the available information
5. Note any limitations due to inability to access the full source content
Be precise and objective in your analysis.`
Line 917 ⟶ 1,033:
{
role: "user",
content:
`I need to verify this claim against a source, but I can only provide the URL since direct content fetching isn't available.
Claim to verify: "${claim}"
Source URL: ${sourceUrl}
Please provide analysis based on what you can determine from the URL and any known information about the source. Note that full verification would require accessing the complete source content.` :
`Claim to verify: "${claim}"
Source information: "${sourceInfo}"`
}
],
|