🐛 fix(manager.py): change cache_manager.set to cache_manager.upsert to update or insert cache value
✨ feat(manager.py): add result_dict to cache instead of directly setting langchain_object to improve cache semantics 🐛 fix(manager.py): handle case when langchain_object is not found in cache and raise ValueError
This commit is contained in:
parent
5df7341eec
commit
20afabd90a
1 changed files with 8 additions and 4 deletions
|
|
@ -170,8 +170,8 @@ class ChatManager:
|
||||||
"""
|
"""
|
||||||
Set the cache for a client.
|
Set the cache for a client.
|
||||||
"""
|
"""
|
||||||
client_id = f"{client_id}_chat"
|
result_dict = {"result": langchain_object, "type": type(langchain_object)}
|
||||||
self.cache_manager.set(client_id, langchain_object)
|
self.cache_manager.upsert(client_id, result_dict)
|
||||||
return client_id in self.cache_manager
|
return client_id in self.cache_manager
|
||||||
|
|
||||||
async def handle_websocket(self, client_id: str, websocket: WebSocket):
|
async def handle_websocket(self, client_id: str, websocket: WebSocket):
|
||||||
|
|
@ -194,9 +194,13 @@ class ChatManager:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with self.cache_manager.set_client_id(client_id):
|
with self.cache_manager.set_client_id(client_id):
|
||||||
langchain_object = self.in_memory_cache.get(f"{client_id}_chat")
|
if langchain_object := self.in_memory_cache.get(client_id).get(
|
||||||
await self.process_message(client_id, payload, langchain_object)
|
"result"
|
||||||
|
):
|
||||||
|
await self.process_message(client_id, payload, langchain_object)
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise ValueError("No langchain object found in cache")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
# Handle any exceptions that might occur
|
# Handle any exceptions that might occur
|
||||||
logger.error(f"Error handling websocket: {exc}")
|
logger.error(f"Error handling websocket: {exc}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue