refac: citations

This commit is contained in:
Timothy Jaeryang Baek 2025-02-15 17:24:29 -08:00
parent 3d0c06ccee
commit bbda717b69
2 changed files with 17 additions and 2 deletions

View File

@ -772,7 +772,7 @@ async def process_chat_payload(request, form_data, metadata, user, model):
if "document" in source:
for doc_idx, doc_context in enumerate(source["document"]):
context_string += f"<source><source_id>{doc_idx}</source_id><source_context>{doc_context}</source_context></source>\n"
context_string += f"<source><source_id>{source_idx}</source_id><source_context>{doc_context}</source_context></source>\n"
context_string = context_string.strip()
prompt = get_last_user_message(form_data["messages"])

View File

@ -17,6 +17,21 @@
return attrs;
}
// Helper function to return only the domain from a URL
function getDomain(url: string): string {
const domain = url.replace('http://', '').replace('https://', '').split(/[/?#]/)[0];
return domain;
}
// Helper function to check if text is a URL and return the domain
function formattedTitle(title: string): string {
if (title.startsWith('http')) {
return getDomain(title);
}
return title;
}
$: attributes = extractAttributes(token.text);
</script>
@ -27,6 +42,6 @@
}}
>
<span class="line-clamp-1">
{attributes.title}
{formattedTitle(attributes.title)}
</span>
</button>