Update app.py
Browse files
app.py
CHANGED
@@ -29,7 +29,7 @@ def generate_preliminary_plan(cluster_data):
|
|
29 |
response = requests.post(
|
30 |
'https://openrouter.ai/api/v1/chat/completions',
|
31 |
headers={
|
32 |
-
'Authorization': f'Bearer {
|
33 |
'HTTP-Referer': 'http://127.0.0.1:5001',
|
34 |
'X-Title': 'Blog Generator'
|
35 |
},
|
@@ -90,7 +90,7 @@ Create the preliminary plan."""
|
|
90 |
logger.error(f"Error in generate_preliminary_plan: {e}")
|
91 |
raise
|
92 |
|
93 |
-
def do_research(plan):
|
94 |
logger.info("Doing research...")
|
95 |
try:
|
96 |
# Extract key points from plan to create search queries
|
@@ -109,7 +109,7 @@ def do_research(plan):
|
|
109 |
|
110 |
# Get research results including both web content and AI analysis
|
111 |
# Using 5 sites per point for more comprehensive research
|
112 |
-
results = research_topic(point, num_sites=5)
|
113 |
|
114 |
if results['success']:
|
115 |
all_research.append({
|
@@ -163,7 +163,7 @@ def generate_blog():
|
|
163 |
|
164 |
# 3. Do research
|
165 |
logger.info("Doing research...")
|
166 |
-
research = do_research(plan)
|
167 |
|
168 |
# 4. Create detailed plan
|
169 |
logger.info("Creating detailed plan...")
|
@@ -295,7 +295,7 @@ def generate_from_csv():
|
|
295 |
plan = generate_preliminary_plan(cluster_data)
|
296 |
|
297 |
# Do research
|
298 |
-
research = do_research(plan)
|
299 |
|
300 |
# Create detailed plan
|
301 |
detailed_plan = blog_gen.create_detailed_plan(cluster_data, plan, research)
|
@@ -360,15 +360,18 @@ def generate_from_csv_text():
|
|
360 |
try:
|
361 |
logger.info("Starting blog generation process for multiple clusters...")
|
362 |
|
363 |
-
# Get CSV content from request JSON
|
364 |
data = request.get_json()
|
365 |
if not data or 'csv_content' not in data:
|
366 |
return jsonify({'error': 'No CSV content provided'}), 400
|
|
|
|
|
367 |
|
368 |
csv_content = data['csv_content']
|
|
|
369 |
|
370 |
-
# Initialize handlers
|
371 |
-
blog_gen = BlogGenerator(OPENAI_API_KEY,
|
372 |
csv_handler = CSVHandler()
|
373 |
|
374 |
# Process the CSV text
|
@@ -384,13 +387,16 @@ def generate_from_csv_text():
|
|
384 |
try:
|
385 |
logger.info(f"Processing cluster with primary keyword: {cluster_data['Primary Keyword']}")
|
386 |
|
|
|
|
|
|
|
387 |
# Generate preliminary plan
|
388 |
logger.info("Generating preliminary plan...")
|
389 |
plan = generate_preliminary_plan(cluster_data)
|
390 |
|
391 |
# Do research
|
392 |
logger.info("Doing research...")
|
393 |
-
research = do_research(plan)
|
394 |
|
395 |
# Create detailed plan
|
396 |
logger.info("Creating detailed plan...")
|
@@ -459,4 +465,4 @@ def generate_from_csv_text():
|
|
459 |
return jsonify({'error': str(e)}), 500
|
460 |
|
461 |
if __name__ == '__main__':
|
462 |
-
app.run(host='
|
|
|
29 |
response = requests.post(
|
30 |
'https://openrouter.ai/api/v1/chat/completions',
|
31 |
headers={
|
32 |
+
'Authorization': f'Bearer {cluster_data["openrouter_key"]}',
|
33 |
'HTTP-Referer': 'http://127.0.0.1:5001',
|
34 |
'X-Title': 'Blog Generator'
|
35 |
},
|
|
|
90 |
logger.error(f"Error in generate_preliminary_plan: {e}")
|
91 |
raise
|
92 |
|
93 |
+
def do_research(plan, openrouter_key):
|
94 |
logger.info("Doing research...")
|
95 |
try:
|
96 |
# Extract key points from plan to create search queries
|
|
|
109 |
|
110 |
# Get research results including both web content and AI analysis
|
111 |
# Using 5 sites per point for more comprehensive research
|
112 |
+
results = research_topic(point, num_sites=5, openrouter_key=openrouter_key)
|
113 |
|
114 |
if results['success']:
|
115 |
all_research.append({
|
|
|
163 |
|
164 |
# 3. Do research
|
165 |
logger.info("Doing research...")
|
166 |
+
research = do_research(plan, OPENROUTER_API_KEY)
|
167 |
|
168 |
# 4. Create detailed plan
|
169 |
logger.info("Creating detailed plan...")
|
|
|
295 |
plan = generate_preliminary_plan(cluster_data)
|
296 |
|
297 |
# Do research
|
298 |
+
research = do_research(plan, OPENROUTER_API_KEY)
|
299 |
|
300 |
# Create detailed plan
|
301 |
detailed_plan = blog_gen.create_detailed_plan(cluster_data, plan, research)
|
|
|
360 |
try:
|
361 |
logger.info("Starting blog generation process for multiple clusters...")
|
362 |
|
363 |
+
# Get CSV content and OpenRouter API key from request JSON
|
364 |
data = request.get_json()
|
365 |
if not data or 'csv_content' not in data:
|
366 |
return jsonify({'error': 'No CSV content provided'}), 400
|
367 |
+
if 'openrouter_key' not in data:
|
368 |
+
return jsonify({'error': 'OpenRouter API key is required'}), 400
|
369 |
|
370 |
csv_content = data['csv_content']
|
371 |
+
openrouter_key = data['openrouter_key']
|
372 |
|
373 |
+
# Initialize handlers with the provided OpenRouter key
|
374 |
+
blog_gen = BlogGenerator(OPENAI_API_KEY, openrouter_key)
|
375 |
csv_handler = CSVHandler()
|
376 |
|
377 |
# Process the CSV text
|
|
|
387 |
try:
|
388 |
logger.info(f"Processing cluster with primary keyword: {cluster_data['Primary Keyword']}")
|
389 |
|
390 |
+
# Add OpenRouter key to cluster_data for use in functions
|
391 |
+
cluster_data['openrouter_key'] = openrouter_key
|
392 |
+
|
393 |
# Generate preliminary plan
|
394 |
logger.info("Generating preliminary plan...")
|
395 |
plan = generate_preliminary_plan(cluster_data)
|
396 |
|
397 |
# Do research
|
398 |
logger.info("Doing research...")
|
399 |
+
research = do_research(plan, openrouter_key)
|
400 |
|
401 |
# Create detailed plan
|
402 |
logger.info("Creating detailed plan...")
|
|
|
465 |
return jsonify({'error': str(e)}), 500
|
466 |
|
467 |
if __name__ == '__main__':
|
468 |
+
app.run(host='127.0.0.1', port=5001, debug=True)
|