File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 12
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
+ import threading
15
16
from abc import ABC , abstractmethod
16
17
from typing import List , Optional , Union
17
18
@@ -93,20 +94,25 @@ class InMemoryMessageHistory(MessageHistory):
93
94
"""
94
95
95
96
def __init__ (self , messages : Optional [List [LLMMessage ]] = None ) -> None :
97
+ self ._lock = threading .Lock ()
96
98
self ._messages = messages or []
97
99
98
100
@property
99
101
def messages (self ) -> List [LLMMessage ]:
100
- return self ._messages
102
+ with self ._lock :
103
+ return self ._messages .copy ()
101
104
102
105
def add_message (self , message : LLMMessage ) -> None :
103
- self ._messages .append (message )
106
+ with self ._lock :
107
+ self ._messages .append (message )
104
108
105
109
def add_messages (self , messages : List [LLMMessage ]) -> None :
106
- self ._messages .extend (messages )
110
+ with self ._lock :
111
+ self ._messages .extend (messages )
107
112
108
113
def clear (self ) -> None :
109
- self ._messages = []
114
+ with self ._lock :
115
+ self ._messages = []
110
116
111
117
112
118
class Neo4jMessageHistory (MessageHistory ):
You can’t perform that action at this time.
0 commit comments