1717from dotenv import load_dotenv
1818
1919from gpt_researcher import GPTResearcher
20- from gpt_researcher .utils .enum import ReportType , Tone
20+ from gpt_researcher .utils .enum import ReportType , ReportSource , Tone
2121from backend .report_type import DetailedReport
22+ from backend .utils import write_md_to_pdf , write_md_to_word
2223
2324# =============================================================================
2425# CLI
101102 default = ""
102103)
103104
105+ # =====================================
106+ # Arg: Report Source
107+ # =====================================
108+
109+ cli .add_argument (
110+ "--report_source" ,
111+ type = str ,
112+ help = "The source of information for the report." ,
113+ choices = ["web" , "local" , "hybrid" , "azure" , "langchain_documents" ,
114+ "langchain_vectorstore" , "static" ],
115+ default = "web"
116+ )
117+
118+ # =====================================
119+ # Arg: Output Format Flags
120+ # =====================================
121+
122+ cli .add_argument (
123+ "--no-pdf" ,
124+ action = "store_true" ,
125+ help = "Skip PDF generation (generate markdown and DOCX only)."
126+ )
127+
128+ cli .add_argument (
129+ "--no-docx" ,
130+ action = "store_true" ,
131+ help = "Skip DOCX generation (generate markdown and PDF only)."
132+ )
133+
104134# =============================================================================
105135# Main
106136# =============================================================================
@@ -145,6 +175,7 @@ async def main(args):
145175 query = args .query ,
146176 query_domains = query_domains ,
147177 report_type = args .report_type ,
178+ report_source = args .report_source ,
148179 tone = tone_map [args .tone ],
149180 encoding = args .encoding
150181 )
@@ -153,14 +184,32 @@ async def main(args):
153184
154185 report = await researcher .write_report ()
155186
156- # Write the report to a file
157- artifact_filepath = f"outputs/{ uuid4 ()} .md"
187+ # Write the report to markdown file
188+ task_id = str (uuid4 ())
189+ artifact_filepath = f"outputs/{ task_id } .md"
158190 os .makedirs ("outputs" , exist_ok = True )
159191 with open (artifact_filepath , "w" , encoding = "utf-8" ) as f :
160192 f .write (report )
161-
162193 print (f"Report written to '{ artifact_filepath } '" )
163194
195+ # Generate PDF if not disabled
196+ if not args .no_pdf :
197+ try :
198+ pdf_path = await write_md_to_pdf (report , task_id )
199+ if pdf_path :
200+ print (f"PDF written to '{ pdf_path } '" )
201+ except Exception as e :
202+ print (f"Warning: PDF generation failed: { e } " )
203+
204+ # Generate DOCX if not disabled
205+ if not args .no_docx :
206+ try :
207+ docx_path = await write_md_to_word (report , task_id )
208+ if docx_path :
209+ print (f"DOCX written to '{ docx_path } '" )
210+ except Exception as e :
211+ print (f"Warning: DOCX generation failed: { e } " )
212+
164213if __name__ == "__main__" :
165214 load_dotenv ()
166215 args = cli .parse_args ()
0 commit comments