Skip to content

Commit

Permalink
footnotes (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
gecBurton authored Dec 15, 2024
1 parent 1c25e03 commit c2aa0b5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,4 @@ def generate_footnote(self, content: str) -> str:
index = content.index(self.text_in_answer) + len(self.text_in_answer)
start = content[:index]
end = content[index:]
return f"{start} [{self.index}]({self.reference} {repr(self.text_in_source)}) {end}"
return f'{start}[^{self.index}]{end}\n\n[^{self.index}]: "{repr(self.text_in_source)[1:-1]}" [source]({self.reference})'
10 changes: 9 additions & 1 deletion core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
<!-- <link rel="manifest" href="/assets/manifest.json">-->
<script src="https://cdn.jsdelivr.net/npm/govuk-frontend@5.7.1/dist/govuk/all.bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/govuk-frontend@5.7.1/dist/govuk/govuk-frontend.min.css">
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown-light.min.css"
integrity="sha512-bm684OXnsiNuQSyrxuuwo4PHqr3OzxPpXyhT66DA/fhl73e1JmBxRKGnO/nRwWvOZxJLRCmNH7FII+Yn1JNPmg=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<!-- <script>-->
<script src="https://cdn.jsdelivr.net/npm/marked-footnote/dist/index.umd.min.js"></script>
<!-- <script>-->
<!-- document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : '');-->
<!-- </script>-->
<title>DoSAC ChatBot</title>
Expand Down
3 changes: 3 additions & 0 deletions core/templates/core/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

{% block content %}
<script>

let buffer = '';
marked.use(markedFootnote());;

document.addEventListener('DOMContentLoaded', function () {
var elements = document.querySelectorAll('.aiMessage');

Expand Down
3 changes: 2 additions & 1 deletion core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
def embedding_detail(request, pk: UUID):
embedding = get_object_or_404(Embedding, pk=pk, document__user=request.user)
context = {
"embedding": embedding, "page_number": embedding.metadata.get("page_number", 0)
"embedding": embedding,
"page_number": embedding.metadata.get("page_number", 0),
}
return render(request, "core/document.html", context)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ def test_chat_annotated_content(chat_message):
index=1,
)

content = chat_message.annotated_content()
assert (
chat_message.annotated_content()
== "the cat [1](www.catfacts.com 'cats are nice') sat on the mat"
content
== 'the cat[^1] sat on the mat\n\n[^1]: "cats are nice" [source](www.catfacts.com)'
)


Expand Down

0 comments on commit c2aa0b5

Please sign in to comment.