Skip to content

Commit

Permalink
cat as singleton ready to go
Browse files Browse the repository at this point in the history
  • Loading branch information
pieroit committed Oct 23, 2023
1 parent 8dadb46 commit 021b4f3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions core/cat/looking_glass/cheshire_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ class CheshireCat():
"""

# CheshireCat is a singleton, this is the instance
_instance = None

# get instance or create as the constructor is called
def __new__(cls):
if not cls._instance:
cls._instance = super().__new__(cls)
cls._instance = CheshireCat()
return cls._instance

def __init__(self):
Expand Down Expand Up @@ -544,5 +545,3 @@ def get_static_path():
"""Allows the Cat expose the static files path."""
log.warning("This method will be removed, import cat.utils tu usit instead.")
return utils.get_static_path()

cat = CheshireCat()
4 changes: 2 additions & 2 deletions core/cat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from cat.routes.static import public, admin, static
from cat.api_auth import check_api_key
from cat.routes.openapi import get_openapi_configuration_function
from cat.looking_glass.cheshire_cat import cat
from cat.looking_glass.cheshire_cat import CheshireCat


@asynccontextmanager
Expand All @@ -26,7 +26,7 @@ async def lifespan(app: FastAPI):
# - Not using midlleware because I can't make it work with both http and websocket;
# - Not using Depends because it only supports callables (not instances)
# - Starlette allows this: https://www.starlette.io/applications/#storing-state-on-the-app-instance
app.state.ccat = cat
app.state.ccat = CheshireCat()

# startup message with admin, public and swagger addresses
log.welcome()
Expand Down
1 change: 0 additions & 1 deletion core/tests/routes/memory/test_memory_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def test_memory_recall_success(client):
episodic_memories = json["vectors"]["collections"]["episodic"]
assert len(episodic_memories) == num_messages # all 3 retrieved


# search with query and k
def test_memory_recall_with_k_success(client):

Expand Down

0 comments on commit 021b4f3

Please sign in to comment.