\n\n"
for section in document['Sections']:
markdown += "
\n\n"
section_number = section['SectionNumber']
section_title = section['Title']
markdown += f"
{section_number}. {section_title}
\n\n"
markdown += f"
\n\n{section['Content']}\n\n
\n\n"
for subsection in section.get('Subsections', []):
subsection_number = subsection['SectionNumber']
subsection_title = subsection['Title']
markdown += f"
{subsection_number} {subsection_title}
\n\n"
markdown += f"
\n\n{subsection['Content']}\n\n
\n\n"
markdown += "
"
return markdown
router = APIRouter()
class DocumentRequest(BaseModel):
query: str
class DocumentResponse(BaseModel):
json_document: Dict
markdown_document: str
@router.post("/generate-document", response_model=DocumentResponse)
async def generate_document_endpoint(request: DocumentRequest):
ai_client = AIClient()
document_generator = DocumentGenerator(ai_client)
try:
# Generate the document
json_document = document_generator.generate_document(request.query)
# Convert to Markdown
markdown_document = MarkdownConverter.convert_to_markdown(json_document["Document"])
return DocumentResponse(
json_document=json_document,
markdown_document=markdown_document
)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))