Skip to content

Commit

Permalink
attempt to fix type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
IMladjenovic committed Dec 20, 2024
1 parent 195f990 commit 0e62eec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/src/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:

Check failure on line 60 in backend/src/llm/llm.py

View workflow job for this annotation

GitHub Actions / Type Checking Backend

Function with declared return type "list[str]" must return value on all code paths   "None" is not assignable to "list[str]" (reportReturnType)
pass

async def delete_all_files(self):
Expand Down
15 changes: 6 additions & 9 deletions backend/src/session/llm_file_upload.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand All @@ -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:
Expand All @@ -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))

0 comments on commit 0e62eec

Please sign in to comment.