diff --git a/chat/services/streaming_question_answering_service.py b/chat/services/streaming_question_answering_service.py index 84f3f52..7448149 100644 --- a/chat/services/streaming_question_answering_service.py +++ b/chat/services/streaming_question_answering_service.py @@ -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. diff --git a/chat/templates/chat/chat.html b/chat/templates/chat/chat.html index 92cd9c5..8ed3e73 100644 --- a/chat/templates/chat/chat.html +++ b/chat/templates/chat/chat.html @@ -8,6 +8,8 @@ {% endblock %} +{% load chat_filters %} + {% block content %}
@@ -76,7 +78,7 @@

{{chat_session.game.name}}

- {{ message.message |linebreaks }} + {{ message.message | markdown_to_html }}

diff --git a/chat/templatetags/chat_filters.py b/chat/templatetags/chat_filters.py new file mode 100644 index 0000000..fe5b7d5 --- /dev/null +++ b/chat/templatetags/chat_filters.py @@ -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)) diff --git a/poetry.lock b/poetry.lock index 758c37b..6941ff4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -839,6 +839,22 @@ files = [ pydantic = ">=1,<2" requests = ">=2,<3" +[[package]] +name = "markdown" +version = "3.7" +description = "Python implementation of John Gruber's Markdown." +category = "main" +optional = false +python-versions = ">=3.8" +files = [ + {file = "Markdown-3.7-py3-none-any.whl", hash = "sha256:7eb6df5690b81a1d7942992c97fad2938e956e79df20cbc6186e9c3a77b1c803"}, + {file = "markdown-3.7.tar.gz", hash = "sha256:2ae2471477cfd02dbbf038d5d9bc226d40def84b4fe2986e49b59b6b472bbed2"}, +] + +[package.extras] +docs = ["mdx-gh-links (>=0.2)", "mkdocs (>=1.5)", "mkdocs-gen-files", "mkdocs-literate-nav", "mkdocs-nature (>=0.6)", "mkdocs-section-index", "mkdocstrings[python]"] +testing = ["coverage", "pyyaml"] + [[package]] name = "marshmallow" version = "3.20.1" @@ -1963,4 +1979,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "3.11.6" -content-hash = "e912d9538bdbf9cec33fccdf63aa2b94c4b5d668f695c0d80f73676418de76af" +content-hash = "4598f527c98a18ed192b2b8df67b2ff51a5375a14438825b40113b53ed37202d" diff --git a/pyproject.toml b/pyproject.toml index b8c15b1..2fb1396 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/rulesbot/settings.py b/rulesbot/settings.py index 7da9d45..994cd7c 100644 --- a/rulesbot/settings.py +++ b/rulesbot/settings.py @@ -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 = [