- Implementation of specialist execution api, including SSE protocol
- eveai_chat becomes deprecated and should be replaced with SSE - Adaptation of STANDARD_RAG specialist - Base class definition allowing to realise specialists with crewai framework - Implementation of SPIN_SPECIALIST - Implementation of test app for testing specialists (test_specialist_client). Also serves as an example for future SSE-based client - Improvements to startup scripts to better handle and scale multiple connections - Small improvements to the interaction forms and views - Caching implementation improved and augmented with additional caches
This commit is contained in:
@@ -60,7 +60,6 @@ class ChatSessionCacheHandler(CacheHandler[CachedSession]):
|
||||
.filter_by(session_id=session_id)
|
||||
.first()
|
||||
)
|
||||
|
||||
if not session:
|
||||
if not create_params:
|
||||
raise ValueError(f"Chat session {session_id} not found and no creation parameters provided")
|
||||
@@ -90,13 +89,13 @@ class ChatSessionCacheHandler(CacheHandler[CachedSession]):
|
||||
for interaction in session.interactions
|
||||
if interaction.specialist_results is not None # Only include completed interactions
|
||||
]
|
||||
|
||||
return CachedSession(
|
||||
cached_session = CachedSession(
|
||||
id=session.id,
|
||||
session_id=session_id,
|
||||
interactions=cached_interactions,
|
||||
timezone=session.timezone
|
||||
)
|
||||
return cached_session
|
||||
|
||||
return self.get(creator_func, session_id=session_id)
|
||||
|
||||
@@ -126,16 +125,17 @@ class ChatSessionCacheHandler(CacheHandler[CachedSession]):
|
||||
)
|
||||
)
|
||||
|
||||
# Force cache update
|
||||
self.invalidate(session_id=session_id)
|
||||
# Update cache directly with modified session using region's set()
|
||||
key = self.generate_key(session_id=session_id)
|
||||
self.region.set(key, self._to_cache_data(cached_session))
|
||||
|
||||
except ValueError:
|
||||
# If session not in cache yet, load it fresh from DB
|
||||
self.get_cached_session(session_id)
|
||||
|
||||
def to_cache_data(self, instance: CachedSession) -> Dict[str, Any]:
|
||||
def _to_cache_data(self, instance: CachedSession) -> Dict[str, Any]:
|
||||
"""Convert CachedSession to cache data"""
|
||||
return {
|
||||
cached_data = {
|
||||
'id': instance.id,
|
||||
'session_id': instance.session_id,
|
||||
'timezone': instance.timezone,
|
||||
@@ -148,8 +148,9 @@ class ChatSessionCacheHandler(CacheHandler[CachedSession]):
|
||||
],
|
||||
'last_updated': dt.now(tz=tz.utc).isoformat()
|
||||
}
|
||||
return cached_data
|
||||
|
||||
def from_cache_data(self, data: Dict[str, Any], session_id: str, **kwargs) -> CachedSession:
|
||||
def _from_cache_data(self, data: Dict[str, Any], session_id: str, **kwargs) -> CachedSession:
|
||||
"""Create CachedSession from cache data"""
|
||||
interactions = [
|
||||
CachedInteraction(
|
||||
@@ -166,14 +167,14 @@ class ChatSessionCacheHandler(CacheHandler[CachedSession]):
|
||||
timezone=data['timezone']
|
||||
)
|
||||
|
||||
def should_cache(self, value: Dict[str, Any]) -> bool:
|
||||
def _should_cache(self, value: Dict[str, Any]) -> bool:
|
||||
"""Validate cache data"""
|
||||
required_fields = {'id','session_id', 'timezone', 'interactions'}
|
||||
required_fields = {'id', 'session_id', 'timezone', 'interactions'}
|
||||
return all(field in value for field in required_fields)
|
||||
|
||||
|
||||
# Register the handler with the cache manager
|
||||
cache_manager.register_handler(ChatSessionCacheHandler, 'eveai_chat_workers')
|
||||
def register_chat_session_cache_handlers(cache_manager):
|
||||
cache_manager.register_handler(ChatSessionCacheHandler, 'eveai_chat_workers')
|
||||
|
||||
|
||||
# Helper function similar to get_model_variables
|
||||
|
||||
Reference in New Issue
Block a user