-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'valentimarco-develop' into develop
- Loading branch information
Showing
9 changed files
with
202 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from typing import Dict | ||
from fastapi import Request, APIRouter, HTTPException, Depends | ||
|
||
from cat.looking_glass.cheshire_cat import CheshireCat | ||
from cat.auth.connection import HTTPAuth | ||
from cat.auth.permissions import AuthPermission, AuthResource | ||
from cat.memory.vector_memory import VectorMemory | ||
from cat.looking_glass.stray_cat import StrayCat | ||
|
||
router = APIRouter() | ||
|
||
# GET collection list with some metadata | ||
@router.get("/collections") | ||
async def get_collections( | ||
request: Request, | ||
stray: StrayCat = Depends(HTTPAuth(AuthResource.MEMORY, AuthPermission.READ)) | ||
) -> Dict: | ||
"""Get list of available collections""" | ||
|
||
vector_memory: VectorMemory = stray.memory.vectors | ||
collections = list(vector_memory.collections.keys()) | ||
|
||
collections_metadata = [] | ||
for c in collections: | ||
coll_meta = vector_memory.get_collection(c) | ||
collections_metadata.append({ | ||
"name": c, | ||
"vectors_count": coll_meta.points_count | ||
}) | ||
|
||
return {"collections": collections_metadata} | ||
|
||
|
||
# DELETE all collections | ||
@router.delete("/collections") | ||
async def wipe_collections( | ||
request: Request, | ||
stray: StrayCat = Depends(HTTPAuth(AuthResource.MEMORY, AuthPermission.DELETE)), | ||
) -> Dict: | ||
"""Delete and create all collections""" | ||
|
||
vector_memory: VectorMemory = stray.memory.vectors | ||
collections = list(vector_memory.collections.keys()) | ||
|
||
to_return = {} | ||
for c in collections: | ||
ret = vector_memory.delete_collection(c) | ||
to_return[c] = ret | ||
|
||
ccat: CheshireCat = request.app.state.ccat | ||
ccat.load_memory() # recreate the long term memories | ||
ccat.mad_hatter.find_plugins() | ||
|
||
return { | ||
"deleted": to_return, | ||
} | ||
|
||
|
||
# DELETE one collection | ||
@router.delete("/collections/{collection_id}") | ||
async def wipe_single_collection( | ||
request: Request, | ||
collection_id: str, | ||
stray: StrayCat = Depends(HTTPAuth(AuthResource.MEMORY, AuthPermission.DELETE)), | ||
) -> Dict: | ||
"""Delete and recreate a collection""" | ||
|
||
vector_memory: VectorMemory = stray.memory.vectors | ||
collections = list(vector_memory.collections.keys()) | ||
|
||
if collection_id not in collections: | ||
raise HTTPException( | ||
status_code=400, detail={"error": "Collection does not exist."} | ||
) | ||
|
||
to_return = {} | ||
ret = vector_memory.delete_collection(collection_id) | ||
to_return[collection_id] = ret | ||
|
||
ccat: CheshireCat = request.app.state.ccat | ||
ccat.load_memory() # recreate the long term memories | ||
ccat.mad_hatter.find_plugins() | ||
|
||
return { | ||
"deleted": to_return, | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
|
||
from typing import Dict | ||
from fastapi import Request, APIRouter, Depends | ||
|
||
from cat.auth.connection import HTTPAuth | ||
from cat.auth.permissions import AuthPermission, AuthResource | ||
from cat.looking_glass.stray_cat import StrayCat | ||
|
||
|
||
router = APIRouter() | ||
|
||
|
||
# DELETE conversation history from working memory | ||
@router.delete("/conversation_history") | ||
async def wipe_conversation_history( | ||
request: Request, | ||
stray: StrayCat = Depends(HTTPAuth(AuthResource.MEMORY, AuthPermission.DELETE)), | ||
) -> Dict: | ||
"""Delete the specified user's conversation history from working memory""" | ||
|
||
stray.working_memory.history = [] | ||
|
||
return { | ||
"deleted": True, | ||
} | ||
|
||
|
||
# GET conversation history from working memory | ||
@router.get("/conversation_history") | ||
async def get_conversation_history( | ||
request: Request, | ||
stray: StrayCat = Depends(HTTPAuth(AuthResource.MEMORY, AuthPermission.READ)), | ||
) -> Dict: | ||
"""Get the specified user's conversation history from working memory""" | ||
|
||
return {"history": stray.working_memory.history} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from fastapi import APIRouter | ||
|
||
from .points import router as points_router | ||
from .collections import router as collections_router | ||
from .convo_history import router as convo_history_router | ||
|
||
memory_router = APIRouter() | ||
|
||
memory_router.include_router(points_router, tags=["Vector Memory - Points"]) | ||
memory_router.include_router(collections_router, tags=["Vector Memory - Collections"]) | ||
memory_router.include_router(convo_history_router, tags=["Working Memory - Current Conversation"]) |
Oops, something went wrong.