From 0e62eecb1e670f3a504b754b78f9c8f058608178 Mon Sep 17 00:00:00 2001 From: "Ivan Mladjenovic (He/Him)" Date: Fri, 20 Dec 2024 12:18:05 +0000 Subject: [PATCH] attempt to fix type checking --- backend/src/llm/llm.py | 2 +- backend/src/session/llm_file_upload.py | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/backend/src/llm/llm.py b/backend/src/llm/llm.py index e56e9d37..2ed0d004 100644 --- a/backend/src/llm/llm.py +++ b/backend/src/llm/llm.py @@ -57,7 +57,7 @@ def chat_with_file( class LLMFileUploadManager(ABC): - async def upload_files(self, files: list[LLMFile]): + async def upload_files(self, files: list[LLMFile]) -> list[str]: pass async def delete_all_files(self): diff --git a/backend/src/session/llm_file_upload.py b/backend/src/session/llm_file_upload.py index 5370c336..920d464d 100644 --- a/backend/src/session/llm_file_upload.py +++ b/backend/src/session/llm_file_upload.py @@ -1,11 +1,9 @@ import json import logging -from typing import TypedDict import redis from src.utils.json import try_parse_to_json -# from .redis_session_middleware import get_session, set_session from src.utils import Config logger = logging.getLogger(__name__) @@ -18,12 +16,11 @@ def get_all_files() -> list[dict[str, str]]: session = redis_client.get(UPLOAD_SESSION_KEY) - return try_parse_to_json(redis_client.get(UPLOAD_SESSION_KEY)) if session else [] - - -class LLMFileUpload(TypedDict): - file_id: str - filename: str + if session and isinstance(session, str): + data = try_parse_to_json(session) + if isinstance(data, list): + return data + return [] def get_llm_file_upload(filename: str) -> str | None: @@ -38,5 +35,5 @@ def add_llm_file_upload(file_id: str, filename: str): files = get_all_files() if not files: files = [] - files.append(LLMFileUpload(file_id=file_id, filename=filename)) + files.append({"file_id": file_id, "filename": filename}) redis_client.set(UPLOAD_SESSION_KEY, json.dumps(files))