Skip to content

Commit d32c70c

Browse files
updating UI and agent functionality
1 parent b0e38ea commit d32c70c

12 files changed

Lines changed: 382 additions & 329 deletions
254 Bytes
Binary file not shown.
-462 Bytes
Binary file not shown.
-498 Bytes
Binary file not shown.

ui/agents/citation_propagator.py

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616

1717
def propagate_citations(contradicted_papers):
1818
"""For each contradicted paper, find recent papers or articles citing it using Perplexity web search."""
19+
print(f"🔍 Citation Agent: Received {len(contradicted_papers) if contradicted_papers else 0} papers")
20+
print(f"🔍 Citation Agent: Papers data: {contradicted_papers}")
21+
1922
# Input validation
2023
if not contradicted_papers or not isinstance(contradicted_papers, list) or len(contradicted_papers) == 0:
24+
print("🔍 Citation Agent: No valid papers received")
2125
return {}
2226

27+
2328
try:
2429
client = OpenAI(api_key=PERPLEXITY_API_KEY, base_url="https://api.perplexity.ai")
2530
citation_cascades = {}
@@ -39,19 +44,23 @@ def propagate_citations(contradicted_papers):
3944
)
4045

4146
try:
47+
print(f"🔍 Citation Agent: Searching citations for: {paper_title}")
48+
# Use same cheap model as agent 1
4249
response = client.chat.completions.create(
43-
model="sonar-reasoning", # Or "sonar-small-chat"; experiment for accuracy
50+
model="sonar", # Use same model as contradiction detector
4451
messages=[
4552
{"role": "system", "content": SYSTEM_PROMPT},
4653
{"role": "user", "content": f"Find papers citing: {paper_title}"},
4754
],
4855
temperature=0.2,
4956
)
57+
print(f"🔍 Citation Agent: Got response for {paper_title}")
5058

5159
# Parse the results—these are actual web-search-derived citations
5260
citing_papers = []
5361
if response.choices and len(response.choices) > 0:
5462
content = response.choices[0].message.content
63+
print(f"🔍 Citation Agent: Response content for {paper_title}: {content[:300]}...")
5564
if content and "Title:" in content:
5665
lines = content.strip().split("\n")
5766
for line in lines:
@@ -69,53 +78,30 @@ def propagate_citations(contradicted_papers):
6978
if title:
7079
citing_papers.append(title)
7180

72-
# If no papers found, use demo data for this specific paper
81+
# If no papers found, log it but keep empty list
7382
if not citing_papers:
74-
if "Large Language Models Still Cannot Plan" in paper_title:
75-
citing_papers = [
76-
"Planning with Large Language Models for Code Generation: Recent Advances and Challenges",
77-
"A Systematic Review of LLM Limitations in Complex Reasoning Tasks",
78-
"Beyond Pattern Matching: Towards True AI Reasoning Capabilities"
79-
]
80-
elif "Reasoning Abilities" in paper_title:
81-
citing_papers = [
82-
"Rethinking Evaluation Metrics for Large Language Model Reasoning",
83-
"The Illusion of Understanding in Large Language Models",
84-
"Cognitive Architectures vs. Large Language Models: A Comparative Study"
85-
]
86-
else:
87-
citing_papers = [
88-
"Emergent Capabilities in AI: Reality or Statistical Artifact?",
89-
"Training Data Memorization vs. Genuine Learning in LLMs",
90-
"Critical Analysis of Emergent Behaviors in Neural Networks"
91-
]
83+
print(f"⚠️ No citing papers found for: {paper_title}")
9284

93-
citation_cascades[paper_title] = citing_papers
85+
# Remove duplicates from citing papers
86+
unique_citing_papers = []
87+
seen_papers = set()
88+
for paper in citing_papers:
89+
paper_lower = paper.lower().strip()
90+
if paper_lower not in seen_papers:
91+
seen_papers.add(paper_lower)
92+
unique_citing_papers.append(paper)
93+
94+
citation_cascades[paper_title] = unique_citing_papers
9495

9596
except Exception as e:
96-
print(f"Error processing paper '{paper_title}': {str(e)}")
97+
print(f"⚠️ Error processing paper '{paper_title}': {str(e)}")
98+
print(f"⚠️ Error type: {type(e)}")
99+
print(f"⚠️ Full error details: {repr(e)}")
97100
citation_cascades[paper_title] = []
98101

99102
return citation_cascades
100103

101104
except Exception as e:
102105
print(f"Error in propagate_citations: {str(e)}")
103-
# Return demo data for demonstration purposes
104-
return {
105-
"Large Language Models Still Cannot Plan: A Benchmark Study": [
106-
"Planning with Large Language Models for Code Generation: Recent Advances and Challenges",
107-
"A Systematic Review of LLM Limitations in Complex Reasoning Tasks",
108-
"Beyond Pattern Matching: Towards True AI Reasoning Capabilities"
109-
],
110-
"On the Reasoning Abilities of Large Language Models: A Critical Analysis": [
111-
"Rethinking Evaluation Metrics for Large Language Model Reasoning",
112-
"The Illusion of Understanding in Large Language Models",
113-
"Cognitive Architectures vs. Large Language Models: A Comparative Study"
114-
],
115-
"Emergent Abilities of Large Language Models Are Not What They Seem": [
116-
"Emergent Capabilities in AI: Reality or Statistical Artifact?",
117-
"Training Data Memorization vs. Genuine Learning in LLMs",
118-
"Critical Analysis of Emergent Behaviors in Neural Networks"
119-
]
120-
}
106+
return {}
121107

ui/agents/contradiction_detector.py

Lines changed: 51 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -30,89 +30,74 @@ def detect_contradictions(claim: str) -> list:
3030
# Craft a prompt to find scientific papers that contradict your claim.
3131
# Perplexity will do live web search and extract sources.
3232
SYSTEM_PROMPT = (
33-
"You are an expert scientific researcher. Identify recent academic papers or "
34-
"articles that directly address or contradict the following research claim. "
35-
"For each, provide the title and a brief excerpt supporting the contradiction. "
36-
"Only include papers found via real-time web search. Format each as: "
37-
"Title: [title] | Excerpt: [relevant text]"
33+
"Find academic papers that contradict this research claim. "
34+
"For each paper, respond with exactly this format:\n"
35+
"PAPER 1:\n"
36+
"Title: [paper title]\n"
37+
"Excerpt: [contradiction excerpt]\n\n"
38+
"PAPER 2:\n"
39+
"Title: [paper title]\n"
40+
"Excerpt: [contradiction excerpt]\n\n"
41+
"Find at least 2-3 papers that challenge this claim."
3842
)
3943

4044
response = client.chat.completions.create(
41-
model="sonar-reasoning", # Uses Perplexity's real-time web search model
45+
model="sonar", # Use fastest, cheapest model
4246
messages=[
4347
{"role": "system", "content": SYSTEM_PROMPT},
4448
{"role": "user", "content": claim},
4549
],
4650
temperature=0.2,
4751
)
4852

49-
# Parse the results—these are actual web-search-derived contradictions.
53+
# Parse the results with simpler logic
5054
results = []
5155
if response.choices and len(response.choices) > 0:
5256
content = response.choices[0].message.content
53-
if content and "Title:" in content:
54-
# Split by lines and process each title/excerpt pair
55-
lines = content.strip().split("\n")
56-
current_title = ""
57-
current_excerpt = ""
58-
57+
print(f"🔍 Contradiction response: {content[:300]}...")
58+
59+
if content:
60+
# Split by PAPER sections
61+
papers = content.split("PAPER")
62+
for paper_section in papers:
63+
if "Title:" in paper_section and "Excerpt:" in paper_section:
64+
lines = paper_section.strip().split("\n")
65+
title = ""
66+
excerpt = ""
67+
68+
for line in lines:
69+
if line.startswith("Title:"):
70+
title = line.replace("Title:", "").strip()
71+
elif line.startswith("Excerpt:"):
72+
excerpt = line.replace("Excerpt:", "").strip()
73+
74+
if title and excerpt:
75+
results.append({"title": title, "excerpt": excerpt})
76+
77+
# If still no results, try basic parsing
78+
if not results and "Title:" in content:
79+
lines = content.split("\n")
5980
for line in lines:
60-
line = line.strip()
61-
if line.startswith("Title:"):
62-
# Save previous entry if exists
63-
if current_title:
64-
results.append({"title": current_title, "excerpt": current_excerpt})
65-
# Start new entry
66-
if "| Excerpt:" in line:
67-
parts = line.split("| Excerpt:")
68-
current_title = parts[0].replace("Title:", "").strip()
69-
current_excerpt = parts[1].strip() if len(parts) > 1 else ""
70-
else:
71-
current_title = line.replace("Title:", "").strip()
72-
current_excerpt = ""
73-
elif line.startswith("Excerpt:") or (current_title and line and not line.startswith("Title:")):
74-
if line.startswith("Excerpt:"):
75-
current_excerpt = line.replace("Excerpt:", "").strip()
76-
else:
77-
current_excerpt += " " + line
78-
79-
# Don't forget the last entry
80-
if current_title:
81-
results.append({"title": current_title, "excerpt": current_excerpt})
81+
if line.startswith("Title:") or "Title:" in line:
82+
# Simple extraction
83+
title = line.split("Title:")[-1].strip()
84+
if title:
85+
results.append({"title": title, "excerpt": "Contradictory evidence found"})
8286

83-
# If no proper parsing worked, fallback to demo data
8487
if not results:
85-
results = [
86-
{
87-
"title": "Large Language Models Still Cannot Plan: A Benchmark Study",
88-
"excerpt": "Despite recent advances, our comprehensive evaluation shows that current LLMs exhibit significant limitations in multi-step reasoning and planning tasks, contradicting claims about their reasoning capabilities."
89-
},
90-
{
91-
"title": "On the Reasoning Abilities of Large Language Models: A Critical Analysis",
92-
"excerpt": "We demonstrate through systematic testing that LLMs primarily rely on pattern matching rather than genuine logical reasoning, revealing fundamental gaps in their cognitive abilities."
93-
},
94-
{
95-
"title": "Emergent Abilities of Large Language Models Are Not What They Seem",
96-
"excerpt": "Our analysis suggests that apparent reasoning capabilities in LLMs are largely artifacts of training data memorization rather than true emergent reasoning abilities."
97-
}
98-
]
88+
print(f"⚠️ Could not parse contradictions from response: {content[:500]}...")
9989

100-
return results
90+
# Remove duplicates based on title
91+
unique_results = []
92+
seen_titles = set()
93+
for paper in results:
94+
title_lower = paper['title'].lower().strip()
95+
if title_lower not in seen_titles:
96+
seen_titles.add(title_lower)
97+
unique_results.append(paper)
98+
99+
return unique_results
101100

102101
except Exception as e:
103102
print(f"Error in detect_contradictions: {str(e)}")
104-
# Return demo data for demonstration purposes
105-
return [
106-
{
107-
"title": "Large Language Models Still Cannot Plan: A Benchmark Study",
108-
"excerpt": "Despite recent advances, our comprehensive evaluation shows that current LLMs exhibit significant limitations in multi-step reasoning and planning tasks, contradicting claims about their reasoning capabilities."
109-
},
110-
{
111-
"title": "On the Reasoning Abilities of Large Language Models: A Critical Analysis",
112-
"excerpt": "We demonstrate through systematic testing that LLMs primarily rely on pattern matching rather than genuine logical reasoning, revealing fundamental gaps in their cognitive abilities."
113-
},
114-
{
115-
"title": "Emergent Abilities of Large Language Models Are Not What They Seem",
116-
"excerpt": "Our analysis suggests that apparent reasoning capabilities in LLMs are largely artifacts of training data memorization rather than true emergent reasoning abilities."
117-
}
118-
]
103+
return []

ui/agents/severity_assessor.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ def generate_synthesis(claim, contradicted_papers, citation_cascades):
7171
)
7272

7373
response = client.chat.completions.create(
74-
model="sonar", # Try the basic sonar model first
74+
model="sonar", # Use same model as other agents
7575
messages=[
7676
{"role": "system", "content": SYSTEM_PROMPT},
7777
{"role": "user", "content": user_prompt},
7878
],
7979
temperature=0.1,
80-
max_tokens=250
8180
)
8281

8382
# Clean the response aggressively to remove thinking process
@@ -100,12 +99,4 @@ def generate_synthesis(claim, contradicted_papers, citation_cascades):
10099

101100
except Exception as e:
102101
print(f"Error in generate_synthesis: {str(e)}")
103-
return """Based on these contradictory findings, there are several research directions to consider:
104-
105-
• **Experimental Validation**: Design controlled experiments to test the specific claims made in your research against the contradictory evidence found
106-
107-
• **Methodological Comparison**: Compare your methodology with the approaches used in the contradictory papers to identify key differences
108-
109-
• **Gap Analysis**: Focus on the specific gaps or limitations highlighted by the contradictory research to refine your approach
110-
111-
Good luck!"""
102+
return "Unable to generate research strategy. Please try again."

ui/backend_server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ async def root():
6666
return {"message": "Research Integrity Network API is running"}
6767

6868
@app.post("/extract_text", response_model=TextExtractionResponse)
69-
async def extract_text_from_pdf(pdf_file: UploadFile = File(...)):
69+
async def extract_text_from_pdf(file: UploadFile = File(...)):
7070
"""
7171
Extract text from uploaded PDF file
7272
"""
7373
try:
74-
if not pdf_file.filename.lower().endswith('.pdf'):
74+
if not file.filename or not file.filename.lower().endswith('.pdf'):
7575
raise HTTPException(status_code=400, detail="File must be a PDF")
7676

7777
# Read the PDF file
78-
pdf_content = await pdf_file.read()
78+
pdf_content = await file.read()
7979
pdf_reader = PdfReader(io.BytesIO(pdf_content))
8080

8181
# Extract text from all pages
@@ -161,5 +161,5 @@ async def analyze_claim_endpoint(request: AnalyzeRequest):
161161
raise HTTPException(status_code=500, detail=f"Error analyzing claim: {str(e)}")
162162

163163
if __name__ == "__main__":
164-
uvicorn.run(app, host="0.0.0.0", port=8502)
164+
uvicorn.run(app, host="0.0.0.0", port=8501)
165165

0 commit comments

Comments
 (0)