Update web_scraper.py
Browse files- web_scraper.py +4 -4
web_scraper.py
CHANGED
@@ -271,11 +271,11 @@ def api_scrape_sites():
|
|
271 |
'error': str(e)
|
272 |
}), 500
|
273 |
|
274 |
-
def analyze_with_gpt(scraped_content, research_query):
|
275 |
"""Analyze scraped content using OpenRouter's Gemini model"""
|
276 |
try:
|
277 |
headers = {
|
278 |
-
'Authorization': f'Bearer {
|
279 |
'HTTP-Referer': 'http://localhost:5001',
|
280 |
'X-Title': 'Research Assistant'
|
281 |
}
|
@@ -320,7 +320,7 @@ Format your response in markdown with proper headings and citations."""
|
|
320 |
print(f"Error in analyze_with_gpt: {str(e)}")
|
321 |
return f"Error analyzing content: {str(e)}"
|
322 |
|
323 |
-
def research_topic(query, num_sites=5):
|
324 |
"""Research a topic using web scraping and GPT analysis"""
|
325 |
try:
|
326 |
# First get web content using existing scrape_site_content function
|
@@ -340,7 +340,7 @@ def research_topic(query, num_sites=5):
|
|
340 |
})
|
341 |
|
342 |
# Get AI analysis of the scraped content
|
343 |
-
analysis = analyze_with_gpt(formatted_content, query)
|
344 |
|
345 |
return {
|
346 |
'success': True,
|
|
|
271 |
'error': str(e)
|
272 |
}), 500
|
273 |
|
274 |
+
def analyze_with_gpt(scraped_content, research_query, openrouter_key):
|
275 |
"""Analyze scraped content using OpenRouter's Gemini model"""
|
276 |
try:
|
277 |
headers = {
|
278 |
+
'Authorization': f'Bearer {openrouter_key}',
|
279 |
'HTTP-Referer': 'http://localhost:5001',
|
280 |
'X-Title': 'Research Assistant'
|
281 |
}
|
|
|
320 |
print(f"Error in analyze_with_gpt: {str(e)}")
|
321 |
return f"Error analyzing content: {str(e)}"
|
322 |
|
323 |
+
def research_topic(query, num_sites=5, openrouter_key=None):
|
324 |
"""Research a topic using web scraping and GPT analysis"""
|
325 |
try:
|
326 |
# First get web content using existing scrape_site_content function
|
|
|
340 |
})
|
341 |
|
342 |
# Get AI analysis of the scraped content
|
343 |
+
analysis = analyze_with_gpt(formatted_content, query, openrouter_key) if openrouter_key else "No OpenRouter API key provided for analysis"
|
344 |
|
345 |
return {
|
346 |
'success': True,
|