Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
Metadata for Websites and Documents ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
lvalics committed Feb 22, 2024
1 parent 3343c04 commit 08ca767
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
43 changes: 26 additions & 17 deletions dj_backend_server/api/views/views_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,32 +313,41 @@ def handle_feedback(request):


def metadata_html_append(response_json, session_id):
# Example logic to determine type based on response_json
# This is a placeholder. Adjust according to your actual logic.
type = "document" # or "website", determined dynamically
seen_filenames = set()
metadata_items = []

for metadata_entry in response_json.get("metadata", []):
type = metadata_entry.get("type")
print(f"Type: {type}")
print(f"Original Filename: {metadata_entry.get('original_filename')}")
print(f"Source: {metadata_entry.get('source')}")
print(f"Page: {metadata_entry.get('page')}")
print(f"Bot ID: {metadata_entry.get('bot_id')}")
print(f"ID: {metadata_entry.get('_id')}")

seen_filenames = set()
metadata_items = []
# if the original_filename is the same in for, then show it only one time.
for entry in response_json.get("metadata", []):
original_filename = entry.get("original_filename")
if original_filename not in seen_filenames:
metadata_items.append(
{"source": entry.get("source"), "original_filename": original_filename}
)
seen_filenames.add(original_filename)
if type == "document":
# if the original_filename is the same in for, then show it only one time.
for entry in response_json.get("metadata", []):
original_filename = entry.get("original_filename")
if original_filename not in seen_filenames:
metadata_items.append(
{
"source": entry.get("source"),
"original_filename": original_filename,
}
)
seen_filenames.add(original_filename)

if type == "website":
# if the link is the same in for, then show it only one time.
for entry in response_json.get("metadata", []):
link = entry.get("link")
if link not in seen_filenames:
metadata_items.append({"source": entry.get("source"), "link": link})
seen_filenames.add(link)

return render_to_string(
"widgets/metadata.html",
{
"APP_URL": settings.APP_URL,
"session_id": session_id,
"metadata_items": metadata_items,
"type": type,
},
)
26 changes: 16 additions & 10 deletions dj_backend_server/web/templates/widgets/metadata.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{% load i18n %}
{% load static %}

<div class="my-5">
<div class="w-full block h-px bg-white-200 my-2"></div>
<div style="color: #000; background-color: #c3c3c3; transition: all 0.2s; padding: 0.25rem 0.5rem; border-radius: 0.375rem;">
<div>
{% for item in metadata_items %}
<div style="margin-bottom: 10px;">
<strong>{% trans "Source of data" %}:</strong> <a href = "{{ APP_URL }}/{{ item.source }}" target="_blank" title="{{ item.original_filename }}">{% trans "Download" %}</a><br>
<div class="my-5" style="padding-bottom: 2.5em;">
{% if type == "document" %}
{% for item in metadata_items %}
<div>
<strong>{% trans "Source of data" %}:</strong> <a href = "{{ APP_URL }}/{{ item.source }}" target="_blank" title="{{ item.original_filename }}">{% trans "Download" %}</a>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
{% elif type == "website" %}
{% for item in metadata_items %}
<div>
<strong>{% trans "Webpage to check" %}:</strong> <a href = "{{ item.link }}" target="_blank" title="{{ item.title }}">{% trans "Visit link" %}</a>
</div>
{% endfor %}
{% else %}
<div></div>
{% endif %}
<div><small>{% trans "Generated content may be inaccurate or false. Always doublecheck the result." %}</small></div>
</div>

0 comments on commit 08ca767

Please sign in to comment.