Skip to content

Commit 7fb74e3

Browse files
committed
Simplify S3ChatHistoryManager attributes
1 parent c8087f5 commit 7fb74e3

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

llm-service/app/services/chat_history/chat_history_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class RagStudioChatMessage(BaseModel):
6464

6565

6666
class ChatHistoryManager(metaclass=ABCMeta):
67+
def __init__(self):
68+
pass
69+
6770
@abstractmethod
6871
def retrieve_chat_history(self, session_id: int) -> list[RagStudioChatMessage]:
6972
pass

llm-service/app/services/chat_history/s3_chat_history_manager.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# BUSINESS ADVANTAGE OR UNAVAILABILITY, OR LOSS OR CORRUPTION OF
3636
# DATA.
3737
#
38-
38+
import functools
3939
import json
4040
import logging
4141
from typing import List
@@ -57,18 +57,16 @@
5757
class S3ChatHistoryManager(ChatHistoryManager):
5858
"""Chat history manager that uses S3 for storage."""
5959

60-
def __init__(self, bucket_name: str = settings.document_bucket):
61-
self.bucket_name = bucket_name
60+
def __init__(self):
61+
super().__init__()
62+
self.bucket_name = settings.document_bucket
6263
self.bucket_prefix = settings.document_bucket_prefix
63-
self._s3_client: S3Client | None = None
6464

65-
@property
65+
@functools.cached_property
6666
def s3_client(self) -> S3Client:
6767
"""Lazy initialization of S3 client."""
68-
if self._s3_client is None:
69-
session: Session = boto3.session.Session()
70-
self._s3_client = session.client("s3")
71-
return self._s3_client
68+
session: Session = boto3.session.Session()
69+
return session.client("s3")
7270

7371
def _get_s3_key(self, session_id: int) -> str:
7472
"""Build the S3 key for a session's chat history."""

0 commit comments

Comments
 (0)