mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-05-24 18:50:15 +00:00
fix(models): persist context_length/threshold_tokens/last_prompt_tokens in Session model (#1318 split)
From PR #1341. Co-authored-by: fxd-jason <wujiachen7@gmail.com>
This commit is contained in:
@@ -318,6 +318,8 @@ class Session:
|
||||
context_messages=None,
|
||||
compression_anchor_visible_idx=None,
|
||||
compression_anchor_message_key=None,
|
||||
context_length=None, threshold_tokens=None,
|
||||
last_prompt_tokens=None,
|
||||
**kwargs):
|
||||
self.session_id = session_id or uuid.uuid4().hex[:12]
|
||||
self.title = title
|
||||
@@ -342,6 +344,9 @@ class Session:
|
||||
self.context_messages = context_messages if isinstance(context_messages, list) else []
|
||||
self.compression_anchor_visible_idx = compression_anchor_visible_idx
|
||||
self.compression_anchor_message_key = compression_anchor_message_key
|
||||
self.context_length = context_length
|
||||
self.threshold_tokens = threshold_tokens
|
||||
self.last_prompt_tokens = last_prompt_tokens
|
||||
self._metadata_message_count = None
|
||||
|
||||
@property
|
||||
@@ -361,6 +366,7 @@ class Session:
|
||||
'personality', 'active_stream_id',
|
||||
'pending_user_message', 'pending_attachments', 'pending_started_at',
|
||||
'compression_anchor_visible_idx', 'compression_anchor_message_key',
|
||||
'context_length', 'threshold_tokens', 'last_prompt_tokens',
|
||||
]
|
||||
meta = {k: getattr(self, k, None) for k in METADATA_FIELDS}
|
||||
meta['messages'] = self.messages
|
||||
@@ -452,6 +458,9 @@ class Session:
|
||||
'personality': self.personality,
|
||||
'compression_anchor_visible_idx': self.compression_anchor_visible_idx,
|
||||
'compression_anchor_message_key': self.compression_anchor_message_key,
|
||||
'context_length': self.context_length,
|
||||
'threshold_tokens': self.threshold_tokens,
|
||||
'last_prompt_tokens': self.last_prompt_tokens,
|
||||
'active_stream_id': self.active_stream_id,
|
||||
'is_streaming': _is_streaming_session(
|
||||
self.active_stream_id, active_stream_ids
|
||||
|
||||
@@ -921,6 +921,9 @@ def handle_get(handler, parsed) -> bool:
|
||||
"pending_user_message": getattr(s, "pending_user_message", None),
|
||||
"pending_attachments": getattr(s, "pending_attachments", []) if load_messages else [],
|
||||
"pending_started_at": getattr(s, "pending_started_at", None),
|
||||
"context_length": getattr(s, "context_length", 0) or 0,
|
||||
"threshold_tokens": getattr(s, "threshold_tokens", 0) or 0,
|
||||
"last_prompt_tokens": getattr(s, "last_prompt_tokens", 0) or 0,
|
||||
}
|
||||
# Signal to the frontend that older messages were omitted.
|
||||
# For msg_before paging, compare against the filtered set,
|
||||
|
||||
Reference in New Issue
Block a user