Skip to content
Snippets Groups Projects
Commit ab6fd127 authored by Andréas Livet's avatar Andréas Livet
Browse files

Fix error when faking chat

parent 24ab5b6b
Branches
Tags
No related merge requests found
import json
import uuid
from collections.abc import AsyncGenerator, Sequence
from enum import Enum
from random import randrange
......@@ -45,7 +46,7 @@ ChatEventType = Enum(
async def transform_sofia_chat_response(
sofia_chat_response: AsyncGenerator[str], doc_to_map: Sequence[Document]
sofia_chat_response: AsyncGenerator[str], doc_to_map: Sequence[uuid.UUID]
) -> AsyncGenerator[str]:
"""
Transform sofia_chat response in a format compatible with caradoc based chat
......@@ -85,9 +86,7 @@ async def transform_sofia_chat_response(
document_list = res[ChatEventType.DOCS.value]
viewer_sources = [
{
"id": doc["document_id"]
if len(doc_to_map) == 0
else str(doc_to_map[randrange(len(doc_to_map))].id),
"id": doc["document_id"] if len(doc_to_map) == 0 else str(doc_to_map[randrange(len(doc_to_map))]),
"content": doc["extrait"],
"score": doc["score"],
# Title and filename are not available for now, they'll be retrieve by the front from the DB
......@@ -142,9 +141,9 @@ async def process_message(session: SessionDep, current_user: CurrentUser, chat_m
with user_permissions(current_user):
# Retieve collection documents and map them to the response
documents_to_map: Sequence[Document] = []
documents_to_map: Sequence[uuid.UUID] = []
if settings.CHAT.fake:
sql_req = select(Document).where(Document.collection_id == chat_message.collection_ids[0])
sql_req = select(Document.id).where(Document.collection_id == chat_message.collection_ids[0])
documents_to_map = session.exec(sql_req).all()
statement = select(Collection).where(col(Collection.id).in_(chat_message.collection_ids))
collections = session.exec(statement).all()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment