mirror of
https://github.com/assafelovic/gpt-researcher.git
synced 2024-04-09 14:09:35 +03:00
Adding UI button for downloading report in docx format
This commit is contained in:
@@ -5,7 +5,7 @@ from pydantic import BaseModel
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from gpt_researcher.utils.websocket_manager import WebSocketManager
|
from gpt_researcher.utils.websocket_manager import WebSocketManager
|
||||||
from .utils import write_md_to_pdf
|
from .utils import write_md_to_pdf, write_md_to_word
|
||||||
|
|
||||||
|
|
||||||
class ResearchRequest(BaseModel):
|
class ResearchRequest(BaseModel):
|
||||||
@@ -48,8 +48,12 @@ async def websocket_endpoint(websocket: WebSocket):
|
|||||||
report_type = json_data.get("report_type")
|
report_type = json_data.get("report_type")
|
||||||
if task and report_type:
|
if task and report_type:
|
||||||
report = await manager.start_streaming(task, report_type, websocket)
|
report = await manager.start_streaming(task, report_type, websocket)
|
||||||
path = await write_md_to_pdf(report)
|
# Saving report as pdf
|
||||||
await websocket.send_json({"type": "path", "output": path})
|
pdf_path = await write_md_to_pdf(report)
|
||||||
|
# Saving report as docx
|
||||||
|
docx_path = await write_md_to_word(report)
|
||||||
|
# Returning the path of saved report files
|
||||||
|
await websocket.send_json({"type": "path", "output": {"pdf": pdf_path, "docx": docx_path}})
|
||||||
else:
|
else:
|
||||||
print("Error: not enough parameters provided.")
|
print("Error: not enough parameters provided.")
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,8 @@
|
|||||||
<div id="reportActions">
|
<div id="reportActions">
|
||||||
<div class="alert alert-info" role="alert" id="status"></div>
|
<div class="alert alert-info" role="alert" id="status"></div>
|
||||||
<a id="copyToClipboard" onclick="GPTResearcher.copyToClipboard()" class="btn btn-secondary mt-3" style="margin-right: 10px;">Copy to clipboard</a>
|
<a id="copyToClipboard" onclick="GPTResearcher.copyToClipboard()" class="btn btn-secondary mt-3" style="margin-right: 10px;">Copy to clipboard</a>
|
||||||
<a id="downloadLink" href="#" class="btn btn-secondary mt-3" target="_blank">Download as PDF</a>
|
<a id="downloadLink" href="#" class="btn btn-secondary mt-3" style="margin-right: 10px;" target="_blank">Download as PDF</a>
|
||||||
|
<a id="downloadLinkWord" href="#" class="btn btn-secondary mt-3" target="_blank">Download as WORD</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ const GPTResearcher = (() => {
|
|||||||
} else if (data.type === 'path') {
|
} else if (data.type === 'path') {
|
||||||
updateState("finished")
|
updateState("finished")
|
||||||
updateDownloadLink(data);
|
updateDownloadLink(data);
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -67,8 +66,10 @@ const GPTResearcher = (() => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateDownloadLink = (data) => {
|
const updateDownloadLink = (data) => {
|
||||||
const path = data.output;
|
const pdf_path = data.output.pdf;
|
||||||
document.getElementById("downloadLink").setAttribute("href", path);
|
const docx_path = data.output.docx;
|
||||||
|
document.getElementById("downloadLink").setAttribute("href", pdf_path);
|
||||||
|
document.getElementById("downloadLinkWord").setAttribute("href", docx_path);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateScroll = () => {
|
const updateScroll = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user