download markdown of conversation useful for github or jira
modified: app.py modified: templates/base.html modified: templates/chat.html
This commit is contained in:
parent
b257f766f8
commit
75e637002b
3 changed files with 54 additions and 4 deletions
40
app.py
40
app.py
|
|
@ -314,6 +314,46 @@ def download_chat_history():
|
|||
return response
|
||||
|
||||
|
||||
@app.route("/download_chat_history_md", methods=["GET"])
|
||||
def download_chat_history_md():
|
||||
room_name = request.args.get("room_name")
|
||||
room = get_room(room_name)
|
||||
|
||||
if not room:
|
||||
return jsonify({"error": "Room not found"}), 404
|
||||
|
||||
messages = Message.query.filter_by(room_id=room.id).all()
|
||||
|
||||
if not messages:
|
||||
return jsonify({"error": "No messages found"}), 404
|
||||
|
||||
# Access system users from the existing context
|
||||
chat_history_md = []
|
||||
toc = []
|
||||
for index, message in enumerate(messages):
|
||||
if not message.is_base64_image(): # Correctly call the method
|
||||
role = "System" if message.username in system_users else "User"
|
||||
header = f"### {role}: {message.username} (Turn {index + 1})"
|
||||
toc.append(
|
||||
f"- [{role}: {message.username} (Turn {index + 1})](#{role.lower()}-{message.username.lower().replace(' ', '-')}-turn-{index + 1})"
|
||||
)
|
||||
chat_history_md.append(f"{header}\n\n{message.content}\n\n---\n")
|
||||
|
||||
if not chat_history_md:
|
||||
return jsonify({"error": "No valid messages found"}), 404
|
||||
|
||||
markdown_content = (
|
||||
f"# Chat History for {room.name}\n\n## Table of Contents\n"
|
||||
+ "\n".join(toc)
|
||||
+ "\n\n"
|
||||
+ "\n".join(chat_history_md)
|
||||
)
|
||||
|
||||
response = Response(response=markdown_content, status=200, mimetype="text/markdown")
|
||||
response.headers["Content-Disposition"] = f'attachment; filename="{room.name}.md"'
|
||||
return response
|
||||
|
||||
|
||||
@app.route("/search")
|
||||
def search_page():
|
||||
# Query all rooms so that newest is first.
|
||||
|
|
|
|||
|
|
@ -163,11 +163,17 @@
|
|||
display: block;
|
||||
padding-right: 0.8em; /* Adjust the padding as needed */
|
||||
}
|
||||
#downloadButton {
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
.download-links {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 10px;
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.download-links a {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@
|
|||
{% block title %}Chatroom{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<a id="downloadButton" href="/download_chat_history?room_name={{ room_name }}" download="chat_history.json">Download Chat History</a>
|
||||
<div class="download-links">
|
||||
<div>
|
||||
Chat History: <a href="/download_chat_history?room_name={{ room_name }}" download="{{ room_name }}.json">JSON</a> or <a href="/download_chat_history_md?room_name={{ room_name }}" download="{{ room_name }}.md">Markdown</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="chat-container">
|
||||
<!-- Chat area where messages will be displayed -->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue