Fix ChatMessageHistory (#9594)

The initialization of the array of ChatMessageHistory is buggy.
The list is shared with all instances.
This commit is contained in:
Philippe PRADOS 2023-08-22 16:36:36 +02:00 committed by GitHub
parent fba29f203a
commit d4c49b16e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
from typing import List
from langchain.pydantic_v1 import BaseModel
from langchain.pydantic_v1 import BaseModel, Field
from langchain.schema import (
BaseChatMessageHistory,
)
@ -13,7 +13,7 @@ class ChatMessageHistory(BaseChatMessageHistory, BaseModel):
Stores messages in an in memory list.
"""
messages: List[BaseMessage] = []
messages: List[BaseMessage] = Field(default_factory=list)
def add_message(self, message: BaseMessage) -> None:
"""Add a self-created message to the store"""