Skip to content

Commit

Permalink
Format markdown nicely in messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorendaugaard committed Sep 11, 2024
1 parent f9afbec commit 66cfa7a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion chat/services/streaming_question_answering_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

prompt_template = """Please use the following information to provide a clear and accurate answer to this question regarding the rules of the game %%GAME%%.
Explain your answer in detail using the rulebook information provided.
If the question is not related to the rules of the specified game, kindly decline to answer.
If the question is not related to the specified game, kindly decline to answer.
If the question is not a question but a greeting or a thank you, kindly respond with a greeting or a thank you.
If the question is claiming that the answer is wrong, kindly respond with an apology.
Ignore any variant or optional rules unless specifically instructed not to.
Expand Down
4 changes: 3 additions & 1 deletion chat/templates/chat/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<meta name="robots" content="noindex, nofollow">
{% endblock %}

{% load chat_filters %}

{% block content %}
<section>
<div class="container py-4">
Expand Down Expand Up @@ -76,7 +78,7 @@ <h4 class="mt-0">{{chat_session.game.name}}</h4>
<div class="card {%if message.message_type == 'ai' %}bg-gray-200{%else%}bg-gray-100{%endif%} text-dark">
<div class="card-body py-2 px-3">
<p class="mb-1 ">
{{ message.message |linebreaks }}
{{ message.message | markdown_to_html }}
</p>
<div class="row">
<div class="col-12 d-flex align-items-left text-sm opacity-6">
Expand Down
19 changes: 19 additions & 0 deletions chat/templatetags/chat_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import markdown
from django import template
from django.utils.safestring import mark_safe

register = template.Library()


@register.filter(name="markdown_to_html", is_safe=True)
def markdown_to_html(value):
"""
Converts Markdown text to HTML.
Args:
value (str): The Markdown text to be converted.
Returns:
str: The HTML representation of the Markdown text.
"""
return mark_safe(markdown.markdown(value))
18 changes: 17 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pillow = "^10.0.0"
django-resized = "^1.0.2"
pymupdf = "^1.23.3"
honcho = "^1.1.0"
markdown = "^3.7"


[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rulesbot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
if IS_HEROKU_APP:
ALLOWED_HOSTS = ["*"]
else:
ALLOWED_HOSTS = ["new.rulesbot.ai", "www.rulesbot.ai", "rulesbot.ai"]
ALLOWED_HOSTS = ["new.rulesbot.ai", "www.rulesbot.ai", "rulesbot.ai", "localhost"]

# Set the domain for the CSRF cookie
CSRF_TRUSTED_ORIGINS = [
Expand Down

0 comments on commit 66cfa7a

Please sign in to comment.