refac: chat completion middleware

This commit is contained in:
Timothy J. Baek
2024-07-01 19:33:58 -07:00
parent b62d2a9b28
commit c7a9b5ccfa
3 changed files with 304 additions and 223 deletions

View File

@@ -294,14 +294,16 @@ def get_rag_context(
extracted_collections.extend(collection_names)
context_string = ""
contexts = []
citations = []
for context in relevant_contexts:
try:
if "documents" in context:
context_string += "\n\n".join(
[text for text in context["documents"][0] if text is not None]
contexts.append(
"\n\n".join(
[text for text in context["documents"][0] if text is not None]
)
)
if "metadatas" in context:
@@ -315,9 +317,7 @@ def get_rag_context(
except Exception as e:
log.exception(e)
context_string = context_string.strip()
return context_string, citations
return contexts, citations
def get_model_path(model: str, update_model: bool = False):