Skip to content

Commit

Permalink
fix chat history class
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchia committed Aug 9, 2024
1 parent 115a6e7 commit 020b4b3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/jupyter-ai/jupyter_ai/history.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Sequence
from typing import List, Sequence, Optional

from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.messages import BaseMessage
Expand All @@ -14,27 +14,27 @@ class BoundedChatHistory(BaseChatMessageHistory, BaseModel):
messages and 2 AI messages.
"""

_messages: List[BaseMessage] = Field(default_factory=list)
all_messages: List[BaseMessage] = Field(default_factory=list, alias='messages')
size: int = 0
k: int

@property
def messages(self) -> List[BaseMessage]:
return self._messages[-self.k * 2 :]
return self.all_messages[-self.k * 2 :]

async def aget_messages(self) -> List[BaseMessage]:
return self.messages

def add_message(self, message: BaseMessage) -> None:
"""Add a self-created message to the store"""
self._messages.append(message)
self.all_messages.append(message)

async def aadd_messages(self, messages: Sequence[BaseMessage]) -> None:
"""Add messages to the store"""
self.add_messages(messages)

def clear(self) -> None:
self._messages = []
self.all_messages = []

async def aclear(self) -> None:
self.clear()

0 comments on commit 020b4b3

Please sign in to comment.