-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument_generator.py
More file actions
executable file
·803 lines (685 loc) · 29.9 KB
/
document_generator.py
File metadata and controls
executable file
·803 lines (685 loc) · 29.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
#!/usr/bin/env python3
"""
Document Generator CLI
Generates draft documents based on writing style, topic, and preferences using AI models.
Supports: Anthropic Claude, OpenAI GPT, Google Gemini
"""
import os
import sys
import re
import argparse
from pathlib import Path
from typing import Optional, Tuple
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Import helper modules
try:
from ai_models import AIModelManager
from google_drive_helper import GoogleDriveHelper
except ImportError as e:
print(f"Error importing helper modules: {e}")
print("Make sure ai_models.py and google_drive_helper.py are in the same directory.")
sys.exit(1)
class DocumentGenerator:
"""Main class for document generation."""
def __init__(self, model_key: str = 'qwen-32b'):
"""Initialize the document generator."""
self.model_key = model_key
self.ai_manager = None
self.google_drive = None
self.style_content = ""
self.topic_content = ""
self.audience = ""
self.output_type = ""
self.size = ""
self.output_location = ""
self.customer_story_content = "" # Optional customer story/case study
# Initialize AI model
try:
self.ai_manager = AIModelManager(model_key)
print(f"✓ Initialized AI Model: {self.ai_manager.name}")
except Exception as e:
print(f"Error initializing AI model: {e}")
sys.exit(1)
# Try to initialize Google Drive (optional)
try:
self.google_drive = GoogleDriveHelper()
print("✓ Google Drive integration available")
except FileNotFoundError as e:
print("ℹ Google Drive integration not configured (optional)")
self.google_drive = None
except Exception as e:
print(f"ℹ Google Drive not available: {e}")
self.google_drive = None
def read_file(self, path: str) -> str:
"""
Read content from a file path or Google Drive link.
Args:
path: Local file path or Google Drive URL
Returns:
Content of the file as string
"""
# Check if it's a Google Drive or Google Docs link
if "drive.google.com" in path or "docs.google.com" in path:
if self.google_drive:
# Determine if it's a Doc or Drive file
if "docs.google.com" in path:
return self.google_drive.read_doc(path)
else:
return self.google_drive.read_file(path)
else:
print("⚠ Google Drive integration not available.")
print("Please set up credentials.json to use Google Drive/Docs.")
return ""
else:
return self.read_local_file(path)
def read_local_file(self, path: str) -> str:
"""Read content from a local file (supports .txt, .md, .docx, .pdf)."""
try:
file_path = Path(path).expanduser()
if not file_path.exists():
print(f"Error: File not found: {path}")
return ""
# Get file extension
ext = file_path.suffix.lower()
# Handle Word documents
if ext in ['.docx', '.doc']:
try:
from docx import Document
doc = Document(file_path)
content = '\n'.join([paragraph.text for paragraph in doc.paragraphs])
print(f"✓ Successfully read {len(content)} characters from Word document {file_path.name}")
return content
except Exception as e:
print(f"Error reading Word document: {e}")
print("Make sure python-docx is installed: pip install python-docx")
return ""
# Handle PDF files
elif ext == '.pdf':
try:
from PyPDF2 import PdfReader
reader = PdfReader(file_path)
content = ''
for page in reader.pages:
content += page.extract_text() + '\n'
print(f"✓ Successfully read {len(content)} characters from PDF {file_path.name}")
return content
except Exception as e:
print(f"Error reading PDF: {e}")
print("Make sure PyPDF2 is installed: pip install PyPDF2")
return ""
# Handle text files (default)
else:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
print(f"✓ Successfully read {len(content)} characters from {file_path.name}")
return content
except Exception as e:
print(f"Error reading file {path}: {e}")
return ""
def get_model_input(self) -> str:
"""Get AI model selection from user."""
print("\n" + "="*60)
print("AI MODEL SELECTION")
print("="*60)
print("Available AI models:\n")
# Build numbered list
model_keys = list(AIModelManager.MODELS.keys())
by_provider = AIModelManager.list_models_by_provider()
index = 1
key_to_number = {}
for provider in ['qwen', 'claude', 'openai', 'gemini']:
if provider in by_provider:
provider_name = {
'qwen': 'Qwen (Local, Free)',
'claude': 'Anthropic Claude',
'openai': 'OpenAI GPT',
'gemini': 'Google Gemini'
}[provider]
print(f"{provider_name}:")
for model in by_provider[provider]:
print(f" {index}. {model['name']}")
key_to_number[str(index)] = model['key']
index += 1
print()
print(f"Default: 1 (Qwen 2.5 32B - Local, Free)")
print()
choice = input("Enter number or model key (or press Enter for default): ").strip()
if not choice:
return "qwen-32b"
# Check if it's a number
if choice in key_to_number:
selected_key = key_to_number[choice]
print(f"✓ Selected: {AIModelManager.MODELS[selected_key]['name']}")
return selected_key
# Check if it's a direct key
if choice in AIModelManager.MODELS:
print(f"✓ Selected: {AIModelManager.MODELS[choice]['name']}")
return choice
# Invalid input
print(f"\n⚠ Invalid selection: '{choice}'")
print("Using default: Qwen 2.5 32B (Local, Free)")
return "qwen-32b"
def get_style_input(self) -> str:
"""Get writing style input from user."""
print("\n" + "="*60)
print("WRITING STYLE & VOICE")
print("="*60)
print("You can provide the writing style in three ways:")
print(" • File path: examples/sample_writing_style.txt")
print(" • Google Drive link: https://docs.google.com/document/d/...")
print(" • Direct text: Type your style description here")
print()
print("Press Enter to use default professional style.")
print()
choice = input("Enter file path, link, or text: ").strip()
if not choice:
print("No input provided. Using default professional style.")
return "Professional, clear, and engaging writing style."
# Check if it's a path or URL
if choice.startswith("http") or choice.startswith("~") or choice.startswith("/") or os.path.exists(choice):
content = self.read_file(choice)
if content:
return content
else:
print("Failed to read file. Please enter style description directly:")
return input("> ").strip()
else:
# It's direct text input
return choice
def get_topic_input(self) -> str:
"""Get topic, insights, and quotes from user."""
print("\n" + "="*60)
print("TOPIC, INSIGHTS & QUOTES")
print("="*60)
print("Provide your topic content (insights, quotes, key points):")
print(" • File path: examples/sample_topic.txt")
print(" • Google Drive link: https://docs.google.com/document/d/...")
print(" • Direct text: Type your topic description here")
print()
print("This field is required.")
print()
choice = input("Enter file path, link, or text: ").strip()
if not choice:
print("Error: Topic information is required.")
sys.exit(1)
# Check if it's a path or URL
if choice.startswith("http") or choice.startswith("~") or choice.startswith("/") or os.path.exists(choice):
content = self.read_file(choice)
if content:
return content
else:
print("Failed to read file. Please enter topic information directly:")
return input("> ").strip()
else:
# It's direct text input
return choice
def get_audience_input(self) -> str:
"""Get target audience from user."""
print("\n" + "="*60)
print("TARGET AUDIENCE")
print("="*60)
print("Who is the target audience for this document?")
print("Examples: business leaders, technical professionals, general public, executives")
print()
audience = input("Target audience: ").strip()
if not audience:
audience = "general professional audience"
print(f"Using default: {audience}")
return audience
def get_output_type_input(self) -> str:
"""Get desired output type from user."""
print("\n" + "="*60)
print("OUTPUT TYPE")
print("="*60)
print("What type of document should be generated?")
print("Examples: blog post, whitepaper, marketing slick, article, report, case study")
print()
output_type = input("Output type: ").strip()
if not output_type:
output_type = "blog post"
print(f"Using default: {output_type}")
return output_type
def get_size_input(self) -> str:
"""Get desired document size from user."""
print("\n" + "="*60)
print("DOCUMENT SIZE")
print("="*60)
print("How long should the document be?")
print("Examples: 1 page, 3 pages, 10 pages, 500 words, 2000 words")
print()
size = input("Document size: ").strip()
if not size:
size = "2-3 pages"
print(f"Using default: {size}")
return size
def get_output_location_input(self) -> str:
"""Get output location from user."""
print("\n" + "="*60)
print("OUTPUT LOCATION")
print("="*60)
print("Where should the document be saved?")
print(" • Directory path: ~/Documents/output (saves as markdown .md file)")
print(" • Google Drive link: https://drive.google.com/drive/folders/... (creates native Google Doc)")
print(" • Type 'docs' to create in Google Docs root")
print(" • Press Enter for current directory")
print()
location = input("Enter directory path or press Enter: ").strip()
if not location:
location = "."
print(f"Using current directory: {os.path.abspath(location)}")
elif location.lower() == 'docs':
location = "docs.google.com"
print("Will create as Google Doc")
return location
def get_customer_story_input(self) -> str:
"""Get optional customer story/case study from user."""
print("\n" + "="*60)
print("CUSTOMER STORY / CASE STUDY (Optional)")
print("="*60)
print("Provide a customer story or case study to include in the document:")
print(" • File path: examples/customer_story.md")
print(" • Google Drive link: https://docs.google.com/document/d/...")
print(" • Press Enter to skip (AI will create a fictional example)")
print()
choice = input("Enter file path, link, or press Enter to skip: ").strip()
if not choice:
print("No customer story provided. AI will create a fictional example.")
return ""
# Check if it's a path or URL
if choice.startswith("http") or choice.startswith("~") or choice.startswith("/") or os.path.exists(choice):
content = self.read_file(choice)
if content:
print(f"✓ Customer story loaded ({len(content)} characters)")
return content
else:
print("Failed to read file. Skipping customer story.")
return ""
else:
# It's direct text input
print(f"✓ Customer story loaded ({len(choice)} characters)")
return choice
def _get_customer_story_instructions(self) -> str:
"""Get customer story instructions based on whether one was provided."""
if self.customer_story_content:
return f"""USE THIS CUSTOMER STORY/CASE STUDY:
{self.customer_story_content}
IMPORTANT: Use the customer story/case study provided above when including examples or case studies in your document. Do not create fictional companies or examples - use the real information provided."""
else:
return """If appropriate for the document type, you may create a realistic but fictional customer story or case study to illustrate key points. Make it specific and credible, not generic."""
def generate_document(self) -> str:
"""Generate the document using selected AI model.
Always generates in markdown format. For Google Docs output,
markdown will be converted to native formatting automatically.
"""
print("\n" + "="*60)
print("GENERATING DOCUMENT...")
print("="*60)
# Always use markdown - will be converted to Google Docs format if needed
format_instructions = """
FORMAT: Use Markdown formatting:
- Use # for the main title (only once at the beginning)
- Use ## for major section headings
- Use ### for subsection headings
- Use **bold** for emphasis (sparingly)
- Use *italic* for subtle emphasis (sparingly)
- Use bullet points with - or *
- Use numbered lists with 1., 2., 3.
"""
# Build the prompt
prompt = f"""You are a professional content writer tasked with creating a {self.output_type}.
WRITING STYLE & VOICE:
{self.style_content}
CRITICAL: Deeply analyze the writing style above. Pay close attention to:
- Sentence structure patterns and rhythm
- Word choice and vocabulary level
- Tone and personality quirks
- How ideas are introduced and developed
- Paragraph structure and flow
- Use of examples, metaphors, or analogies
- Any unique stylistic signatures
Mirror these patterns authentically in your writing.
TARGET AUDIENCE:
{self.audience}
TOPIC, INSIGHTS & QUOTES:
{self.topic_content}
CUSTOMER STORY / CASE STUDY:
{self._get_customer_story_instructions()}
DOCUMENT REQUIREMENTS:
- Type: {self.output_type}
- Length: {self.size}
- Audience: {self.audience}
{format_instructions}
ANTI-AI-PATTERN INSTRUCTIONS (CRITICAL):
Write like a human, not an AI. Specifically avoid these common AI patterns:
❌ AVOID:
- Generic openings ("In today's world...", "In an era of...", "As we navigate...")
- Excessive hedging language ("may," "might," "could potentially," "arguably")
- Formulaic transitions ("Moreover," "Furthermore," "Additionally," "In conclusion")
- Overly enthusiastic or promotional tone
- Lists of abstract concepts without concrete examples
- Perfectly balanced arguments (real writing has a point of view)
- Explaining what you're about to do ("Let's explore...", "We will examine...")
- Meta-commentary about the document itself
✓ INSTEAD:
- Start directly with substance or a specific observation
- Make clear, confident statements when appropriate
- Use natural transitions that flow from ideas
- Vary sentence structure organically (mix short and long)
- Include specific examples, anecdotes, or concrete details
- Write with authentic voice and clear perspective
- Let ideas connect naturally without announcing connections
Generate a complete, well-structured {self.output_type} that:
1. DEEPLY matches the provided writing style and voice (analyze it carefully first)
2. Is tailored to the target audience ({self.audience})
3. Incorporates the topic, insights, and quotes provided naturally
4. Meets the length requirement ({self.size})
5. Sounds like authentic human writing, not AI-generated content
6. Is professionally formatted and ready for publication
Generate the complete document now:"""
try:
# Call AI model
print(f"Sending request to {self.ai_manager.name}...")
content = self.ai_manager.generate(prompt)
print(f"✓ Generated {len(content)} characters")
return content
except Exception as e:
print(f"Error generating document: {e}")
sys.exit(1)
def extract_title_from_content(self, content: str) -> str:
"""Extract title from markdown content (first # heading).
Returns cleaned title suitable for filename, or default if no title found.
"""
import re
lines = content.split('\n')
for line in lines:
# Look for markdown heading
match = re.match(r'^#\s+(.+)$', line.strip())
if match:
title = match.group(1).strip()
# Clean title for filename (remove special characters)
title = re.sub(r'[^\w\s-]', '', title) # Remove special chars except spaces and hyphens
title = re.sub(r'\s+', ' ', title) # Normalize spaces
title = title.strip()
return title[:80] # Limit length to 80 chars
# Fallback if no title found
return f"Generated {self.output_type.title()}"
def _get_model_name_for_filename(self) -> str:
"""Get a clean model name suitable for filename."""
import re
# Get base model name and clean it for filename
model_name = self.ai_manager.name
# Remove parenthetical descriptions like "(Multimodal)" or "(Fast)"
model_name = re.sub(r'\s*\([^)]*\)', '', model_name)
# Replace spaces with hyphens
model_name = model_name.replace(' ', '-')
return model_name
def save_document(self, content: str) -> None:
"""Save the generated document to the specified location."""
print("\n" + "="*60)
print("SAVING DOCUMENT...")
print("="*60)
# Extract title from content for filename
doc_title = self.extract_title_from_content(content)
model_name = self._get_model_name_for_filename()
# Check if it's a Google Drive location
if "drive.google.com" in self.output_location or "docs.google.com" in self.output_location:
if self.google_drive:
# Format: [Title]-[AI Model]-Generated
title = f"{doc_title}-{model_name}-Generated"
# Extract folder ID if it's a folder URL
folder_id = None
if "/folders/" in self.output_location:
folder_id = self.google_drive.extract_file_id(self.output_location)
# Always create as native Google Doc
url = self.google_drive.create_doc(title, content, folder_id=folder_id)
if url:
if folder_id:
print(f"✓ Document saved as Google Doc in folder!")
else:
print(f"✓ Document saved as Google Doc!")
print(f" Title: {title}")
print(f" URL: {url}")
print(f" Size: {len(content)} characters")
return
# If Google Drive save failed, fall back to local
print("⚠ Google Drive save failed, saving locally instead...")
self.output_location = "."
else:
print("⚠ Google Drive integration not available.")
print("Saving to current directory instead.")
self.output_location = "."
# Save locally
# Expand path and create directory if needed
output_path = Path(self.output_location).expanduser()
if not output_path.exists():
output_path.mkdir(parents=True, exist_ok=True)
# Format: [Title]-[AI Model]-Generated.md
filename = f"{doc_title}-{model_name}-Generated.md"
full_path = output_path / filename
# Save the file
try:
with open(full_path, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✓ Document saved successfully!")
print(f" Filename: {filename}")
print(f" Location: {full_path.absolute()}")
print(f" Size: {len(content)} characters")
except Exception as e:
print(f"Error saving document: {e}")
sys.exit(1)
def run_with_args(self, args: argparse.Namespace) -> None:
"""Run with command-line arguments (non-interactive mode)."""
print("\n" + "="*60)
print("DOCUMENT GENERATOR")
print(f"Using: {self.ai_manager.name}")
print("="*60)
# Load style content
if args.style:
if os.path.exists(args.style) or args.style.startswith("~"):
self.style_content = self.read_file(args.style)
if not self.style_content:
print(f"Error: Could not read style file: {args.style}")
sys.exit(1)
else:
self.style_content = args.style
else:
self.style_content = "Professional, clear, and engaging writing style."
# Load topic content
if os.path.exists(args.topic) or args.topic.startswith("~"):
self.topic_content = self.read_file(args.topic)
if not self.topic_content:
print(f"Error: Could not read topic file: {args.topic}")
sys.exit(1)
else:
self.topic_content = args.topic
# Set other parameters
self.audience = args.audience or "general professional audience"
self.output_type = args.type or "blog post"
self.size = args.size or "2-3 pages"
self.output_location = args.output or "."
# Load customer story if provided
if hasattr(args, 'customer_story') and args.customer_story:
if os.path.exists(args.customer_story) or args.customer_story.startswith("~") or args.customer_story.startswith("http"):
self.customer_story_content = self.read_file(args.customer_story)
if not self.customer_story_content:
print(f"Warning: Could not read customer story file: {args.customer_story}")
print("AI will create a fictional example instead.")
else:
self.customer_story_content = args.customer_story
else:
self.customer_story_content = ""
# Display summary
print("\n" + "="*60)
print("CONFIGURATION")
print("="*60)
print(f"AI Model: {self.ai_manager.name}")
print(f"Output Type: {self.output_type}")
print(f"Audience: {self.audience}")
print(f"Size: {self.size}")
print(f"Style Length: {len(self.style_content)} characters")
print(f"Topic Length: {len(self.topic_content)} characters")
if self.customer_story_content:
print(f"Customer Story: {len(self.customer_story_content)} characters")
else:
print(f"Customer Story: None (AI will create fictional example)")
print(f"Output Location: {self.output_location}")
# Generate and save (always uses markdown, converted automatically for Google Docs)
content = self.generate_document()
self.save_document(content)
print("\n" + "="*60)
print("✓ COMPLETE!")
print("="*60)
def run(self) -> None:
"""Run the interactive CLI application."""
print("\n" + "="*60)
print("DOCUMENT GENERATOR")
print("Powered by Multiple AI Models")
print("="*60)
# Get model selection (may reinitialize AI manager)
new_model_key = self.get_model_input()
if new_model_key != self.model_key:
print(f"\nSwitching to {AIModelManager.MODELS[new_model_key]['name']}...")
self.model_key = new_model_key
try:
self.ai_manager = AIModelManager(new_model_key)
print(f"✓ Model switched successfully")
except Exception as e:
print(f"Error switching model: {e}")
sys.exit(1)
# Gather inputs
self.style_content = self.get_style_input()
self.topic_content = self.get_topic_input()
self.audience = self.get_audience_input()
self.output_type = self.get_output_type_input()
self.size = self.get_size_input()
self.output_location = self.get_output_location_input()
self.customer_story_content = self.get_customer_story_input()
# Display summary
print("\n" + "="*60)
print("SUMMARY")
print("="*60)
print(f"AI Model: {self.ai_manager.name}")
print(f"Output Type: {self.output_type}")
print(f"Audience: {self.audience}")
print(f"Size: {self.size}")
print(f"Style Length: {len(self.style_content)} characters")
print(f"Topic Length: {len(self.topic_content)} characters")
if self.customer_story_content:
print(f"Customer Story: {len(self.customer_story_content)} characters")
else:
print(f"Customer Story: None (AI will create fictional example)")
print(f"Output Location: {self.output_location}")
print()
# Confirm before generating
confirm = input("Proceed with document generation? (yes/no): ").strip().lower()
if confirm not in ['yes', 'y']:
print("Cancelled.")
sys.exit(0)
# Generate and save (always uses markdown, converted automatically for Google Docs)
content = self.generate_document()
self.save_document(content)
print("\n" + "="*60)
print("✓ COMPLETE!")
print("="*60)
def main():
"""Main entry point."""
parser = argparse.ArgumentParser(
description="AI-powered document generator using multiple AI models (Qwen, Claude, GPT, Gemini)",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
Interactive mode (default):
python3 document_generator.py
Test mode (default - uses local Qwen 2.5 32B - free):
python3 document_generator.py \\
--topic "examples/sample_topic.txt" \\
--style "examples/sample_writing_style.txt" \\
--audience "business leaders" \\
--type "whitepaper" \\
--size "3 pages" \\
--output "./output"
Production mode (also uses Qwen 2.5 32B - local, free):
python3 document_generator.py \\
--mode production \\
--topic "Write about AI in healthcare" \\
--audience "healthcare executives" \\
--type "blog post"
Override with specific model:
python3 document_generator.py \\
--model claude-3-5-sonnet \\
--topic "Remote work trends" \\
--type "article"
"""
)
parser.add_argument(
"-m", "--model",
default="qwen-32b",
help="AI model to use (default: qwen-32b). Options: qwen-32b, qwen-72b, qwen-14b, qwen-7b, claude-3-5-sonnet, claude-3-5-haiku, claude-3-opus, gpt-4, gpt-4o, gpt-3.5-turbo, gemini-2.5-flash, gemini-2.5-pro, gemini-1.5-pro, gemini-1.5-flash, gemini-pro"
)
parser.add_argument(
"-t", "--topic",
help="Topic content (file path or direct text). Required for non-interactive mode."
)
parser.add_argument(
"-s", "--style",
help="Writing style (file path or direct text). Optional, uses default if not provided."
)
parser.add_argument(
"-a", "--audience",
help="Target audience (e.g., 'business leaders', 'technical professionals')"
)
parser.add_argument(
"--type",
help="Output type (e.g., 'blog post', 'whitepaper', 'article')"
)
parser.add_argument(
"--size",
help="Document size (e.g., '3 pages', '1000 words')"
)
parser.add_argument(
"-c", "--customer-story",
help="Customer story/case study (file path or Google Docs URL). Optional - AI will create fictional example if not provided."
)
parser.add_argument(
"-o", "--output",
help="Output location (directory path or Google Drive URL)"
)
parser.add_argument(
"--mode",
choices=["test", "production"],
default="test",
help="Operation mode: both 'test' and 'production' use Qwen 2.5 32B (local, free) by default (default: test)"
)
args = parser.parse_args()
# Override model based on mode if not explicitly set
if args.mode == "test":
model_to_use = "qwen-32b"
else: # production
model_to_use = "qwen-32b"
# If user explicitly specified --model, that takes precedence
if args.model != "qwen-32b": # Not the default
model_to_use = args.model
try:
# Initialize with selected model
generator = DocumentGenerator(model_key=model_to_use)
# Print mode information
mode_label = "TEST MODE" if args.mode == "test" else "PRODUCTION MODE"
print(f"\n{'='*60}")
print(f"{mode_label}")
print(f"{'='*60}")
# Check if any arguments were provided (non-interactive mode)
if args.topic:
generator.run_with_args(args)
else:
# No arguments, run in interactive mode
generator.run()
except KeyboardInterrupt:
print("\n\nCancelled by user.")
sys.exit(0)
except Exception as e:
print(f"\nUnexpected error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()