pvanand commited on
Commit
61925fa
1 Parent(s): db1b7b5

Update document_generator.py

Browse files
Files changed (1) hide show
  1. document_generator.py +11 -5
document_generator.py CHANGED
@@ -246,7 +246,7 @@ async def generate_document_stream(document_generator: DocumentGenerator, docume
246
  content = document_generator.generate_content(section_title, content_instruction, section_number)
247
  section["Content"] = content
248
  yield json.dumps({
249
- "type": "document_section",
250
  "content": {
251
  "section_number": section_number,
252
  "section_title": section_title,
@@ -262,7 +262,7 @@ async def generate_document_stream(document_generator: DocumentGenerator, docume
262
  content = document_generator.generate_content(subsection_title, subsection_content_instruction, subsection_number)
263
  subsection["Content"] = content
264
  yield json.dumps({
265
- "type": "document_section",
266
  "content": {
267
  "section_number": subsection_number,
268
  "section_title": subsection_title,
@@ -271,7 +271,10 @@ async def generate_document_stream(document_generator: DocumentGenerator, docume
271
  }) + "\n"
272
 
273
  markdown_document = MarkdownConverter.convert_to_markdown(document_generator.document_outline["Document"])
274
- yield json.dumps({"type": "complete_document", "content": markdown_document}) + "\n"
 
 
 
275
 
276
  @cache(expire=600*24*7)
277
  @router.post("/generate-document/json", response_model=JsonDocumentResponse)
@@ -299,9 +302,12 @@ async def generate_markdown_document_stream_endpoint(request: MarkdownDocumentRe
299
  async for chunk in generate_document_stream(document_generator, request.json_document, request.query):
300
  yield chunk
301
  except Exception as e:
302
- yield json.dumps({"type": "error", "content": str(e)}) + "\n"
 
 
 
303
 
304
- return StreamingResponse(stream_generator(), media_type="application/x-ndjson")
305
 
306
  ###########################################
307
  class MarkdownDocumentResponse(BaseModel):
 
246
  content = document_generator.generate_content(section_title, content_instruction, section_number)
247
  section["Content"] = content
248
  yield json.dumps({
249
+ "type": "document_section",
250
  "content": {
251
  "section_number": section_number,
252
  "section_title": section_title,
 
262
  content = document_generator.generate_content(subsection_title, subsection_content_instruction, subsection_number)
263
  subsection["Content"] = content
264
  yield json.dumps({
265
+ "type": "document_section",
266
  "content": {
267
  "section_number": subsection_number,
268
  "section_title": subsection_title,
 
271
  }) + "\n"
272
 
273
  markdown_document = MarkdownConverter.convert_to_markdown(document_generator.document_outline["Document"])
274
+ yield json.dumps({
275
+ "type": "complete_document",
276
+ "content": markdown_document
277
+ }) + "\n"
278
 
279
  @cache(expire=600*24*7)
280
  @router.post("/generate-document/json", response_model=JsonDocumentResponse)
 
302
  async for chunk in generate_document_stream(document_generator, request.json_document, request.query):
303
  yield chunk
304
  except Exception as e:
305
+ yield json.dumps({
306
+ "type": "error",
307
+ "content": str(e)
308
+ }) + "\n"
309
 
310
+ return StreamingResponse(stream_generator(), media_type="text/plain")
311
 
312
  ###########################################
313
  class MarkdownDocumentResponse(BaseModel):