21 lines
511 B
Python
21 lines
511 B
Python
# All comments are in English.
|
|
|
|
import uuid
|
|
|
|
class ChatStore:
|
|
"""Simple in-memory chat store with multiple conversations."""
|
|
|
|
def __init__(self):
|
|
self.conversations = {}
|
|
|
|
def new_conversation(self):
|
|
cid = str(uuid.uuid4())
|
|
self.conversations[cid] = []
|
|
return cid
|
|
|
|
def add_message(self, cid, role, content):
|
|
self.conversations[cid].append({"role": role, "content": content})
|
|
|
|
def get_messages(self, cid):
|
|
return self.conversations.get(cid, [])
|