Fix retrieving history from distributed instance

This commit is contained in:
doctorpangloss 2024-04-08 14:39:16 -07:00
parent 034ffcea03
commit dd6f7c4215
2 changed files with 7 additions and 3 deletions

View File

@ -204,7 +204,7 @@ class DistributedPromptQueue(AbstractPromptQueue):
"""
return False
def get_history(self, prompt_id: Optional[int] = None, max_items=None, offset=-1) \
def get_history(self, prompt_id: Optional[int] = None, max_items=None, offset=None) \
-> Mapping[str, HistoryEntry]:
return self._caller_history.copy(prompt_id=prompt_id, max_items=max_items, offset=offset)

View File

@ -19,12 +19,16 @@ class History:
def copy(self, prompt_id: Optional[str | int] = None, max_items: Optional[int] = None,
offset: Optional[int] = None) -> Dict[str, HistoryEntry]:
offset = offset or 0
if offset is not None and offset < 0:
offset = max(len(self.history) + offset, 0)
max_items = max_items or MAXIMUM_HISTORY_SIZE
if prompt_id in self.history:
return {prompt_id: copy.deepcopy(self.history[prompt_id])}
else:
return dict(islice(self.history, offset, max_items))
ordered_dict = OrderedDict()
for k in islice(self.history, offset, max_items):
ordered_dict[k] = copy.deepcopy(self.history[k])
return ordered_dict
def clear(self):
self.history.clear()