feat: show RAG query results as citations

This commit is contained in:
Jun Siang Cheah
2024-05-06 21:14:51 +08:00
committed by Timothy J. Baek
parent ba09fcd548
commit 0872bea790
7 changed files with 234 additions and 42 deletions

View File

@@ -320,11 +320,19 @@ def rag_messages(
extracted_collections.extend(collection)
context_string = ""
citations = []
for context in relevant_contexts:
try:
if "documents" in context:
items = [item for item in context["documents"][0] if item is not None]
context_string += "\n\n".join(items)
if "metadatas" in context:
citations.append(
{
"document": context["documents"][0],
"metadata": context["metadatas"][0],
}
)
except Exception as e:
log.exception(e)
context_string = context_string.strip()
@@ -355,7 +363,7 @@ def rag_messages(
messages[last_user_message_idx] = new_user_message
return messages
return messages, citations
def get_model_path(model: str, update_model: bool = False):