Skip to content

Commit

Permalink
refactor: make singleton function more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Sep 19, 2024
1 parent 6119ba0 commit 6bac83c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions server/config.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
from typing import Callable

from pydantic_settings import BaseSettings


def singleton[T](cls: type[T]) -> T:
def singleton[T](callable_object: Callable[[], T]) -> T:
"""
Summary
-------
a decorator to make a class a singleton
a decorator to transform a callable/class to a singleton

Parameters
----------
cls (type[T]) : the class to make a singleton
callable_object (Callable[[], T]) : the callable to transform

Returns
-------
instance (T) : the singleton instance
instance (T) : the singleton
"""
return cls()
return callable_object()
@singleton
Expand All @@ -38,9 +40,9 @@ class Config(BaseSettings):
"""

server_port: int = 49494
server_root_path: str = "/api"
redis_index_name: str = "index"
server_root_path: str = '/api'
redis_index_name: str = 'index'
use_cuda: bool = False
document_index_prefix: str = "doc"
document_index_tag: str = "chat_id"
document_index_prefix: str = 'doc'
document_index_tag: str = 'chat_id'
embedding_dimensions: int = 768

0 comments on commit 6bac83c

Please sign in to comment.