Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

clean up code

LearningCircuit80d12b2df30a
diff --git a/citation_handler.py b/citation_handler.py
index f7865aba1d..52634f8cd7 100644
--- a/citation_handler.py
+++ b/citation_handler.py
@@ -27,7 +27,7 @@ class CitationHandler:
metadata={
"source": result.get("link", f"source_{i+1}"),
"title": result.get("title", f"Source {i+1}"),
- "index": i+1,
+ "index": i + 1,
},
)
)
diff --git a/config.py b/config.py
index 1d4eeddf1d..25ebbf5b26 100644
--- a/config.py
+++ b/config.py
@@ -16,8 +16,8 @@ DEFAULT_TEMPERATURE = 0.7
MAX_TOKENS = 2000
# Search System Settings
-SEARCH_ITERATIONS=3
-QUESTIONS_PER_ITERATION=2
+SEARCH_ITERATIONS = 3
+QUESTIONS_PER_ITERATION = 2
# Search Configuration
MAX_SEARCH_RESULTS = 40 # DuckDuckGoSearch seems to return only 4 results anyways.
diff --git a/full_duck_duck_go_search_results.py b/full_duck_duck_go_search_results.py
index 55ad781f8d..c4aa108fcc 100644
--- a/full_duck_duck_go_search_results.py
+++ b/full_duck_duck_go_search_results.py
@@ -8,6 +8,7 @@ import json, os
from utilities import remove_think_tags
from datetime import datetime
+
class FullDuckDuckGoSearchResults:
def __init__(
self,
@@ -28,7 +29,6 @@ class FullDuckDuckGoSearchResults:
self.safesearch = safesearch
os.environ["USER_AGENT"] = "Local Deep Research/1.0"
-
self.ddg_search = DuckDuckGoSearchResults(
output_format=output_format,
max_results=self.max_results,
@@ -53,7 +53,6 @@ class FullDuckDuckGoSearchResults:
]
)
-
now = datetime.now()
current_time = now.strftime("%Y-%m-%d")
prompt = f"""ONLY Return a JSON array. The response contains no letters. Be very strict. Evaluate these URLs and their content for timeliness (today: {current_time}) known reliable near-academic sources (e.g., academic or government sources) and query relevance. query: {query}
@@ -67,7 +66,7 @@ Example response: \n[0, 2, 4]\n\n"""
try:
# Get LLM's evaluation
response = self.llm.invoke(prompt)
- #print(response)
+ # print(response)
good_indices = json.loads(remove_think_tags(response.content))
# Return only the results with good URLs
@@ -84,7 +83,7 @@ Example response: \n[0, 2, 4]\n\n"""
return cleaned
def run(self, query: str):
- nr_full_text=0
+ nr_full_text = 0
# Step 1: Get search results from DuckDuckGo
search_results = self.ddg_search.invoke(query)
if not isinstance(search_results, list):
diff --git a/main.py b/main.py
index 1405dc9172..248ec680e9 100644
--- a/main.py
+++ b/main.py
@@ -87,7 +87,9 @@ def main():
# Quick Summary
print("\n=== QUICK SUMMARY ===")
if results["findings"] and len(results["findings"]) > 0:
- initial_analysis = [finding["content"] for finding in results["findings"]]
+ initial_analysis = [
+ finding["content"] for finding in results["findings"]
+ ]
print(initial_analysis)
else:
diff --git a/search_system.py b/search_system.py
index 4885ecaeba..ac3d7c9a91 100644
--- a/search_system.py
+++ b/search_system.py
@@ -6,6 +6,7 @@ from config import get_llm, get_search, SEARCH_ITERATIONS, QUESTIONS_PER_ITERATI
from citation_handler import CitationHandler
from datetime import datetime
+
class AdvancedSearchSystem:
def __init__(self):
self.search = get_search()
@@ -35,7 +36,8 @@ class AdvancedSearchSystem:
q.replace("Q:", "").strip()
for q in remove_think_tags(response.content).split("\n")
if q.strip().startswith("Q:")
- ][:self.questions_per_iteration]
+ ][: self.questions_per_iteration]
+
def _compress_knowledge(self, current_knowledge: str, query: str) -> List[str]:
now = datetime.now()
current_time = now.strftime("%Y-%m-%d")
@@ -47,7 +49,7 @@ class AdvancedSearchSystem:
\n\n\nFormat: text summary\n\n"""
response = self.model.invoke(prompt)
return remove_think_tags(response.content)
-
+
def analyze_topic(self, query: str) -> Dict:
findings = []
current_knowledge = ""
@@ -64,11 +66,10 @@ class AdvancedSearchSystem:
else current_knowledge
)
print("len search", len(search_results))
- #print(search_results)
- if len(search_results) ==0:
+ # print(search_results)
+ if len(search_results) == 0:
continue
-
result = self.citation_handler.analyze_followup(
question, search_results, limited_knowledge
)
@@ -82,7 +83,7 @@ class AdvancedSearchSystem:
}
)
current_knowledge += f"\n\n{result['content']}"
-
+
iteration += 1
current_knowledge = self._compress_knowledge(current_knowledge, query)
self._save_findings(findings, current_knowledge, query)
diff --git a/utilities.py b/utilities.py
index afc07da4c5..f47118aa64 100644
--- a/utilities.py
+++ b/utilities.py
@@ -69,8 +69,8 @@ def format_findings_to_text(findings_list, current_knowledge, questions_by_itera
# Search results if they exist
if "search_results" in finding:
- #formatted_text += "SEARCH RESULTS:\n"
- #formatted_text += f"{finding['search_results']}\n\n"
+ # formatted_text += "SEARCH RESULTS:\n"
+ # formatted_text += f"{finding['search_results']}\n\n"
# Extract and format links for this finding
links = extract_links_from_search_results(finding["search_results"])