Spaces:
Runtime error
Runtime error
File size: 1,224 Bytes
eabc9cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import uuid
from utils.local_storage import read_from_local, save_to_local, remove_from_local
from utils.constants import DATA_DIR
def is_conversation_storage_exist(id: str) -> bool:
# Check if conversation exist
return read_from_local(f"{id}.json", DATA_DIR) is not None
def get_conversation_storage(id: str) -> list:
# Get conversation
conversation = read_from_local(f"{id}.json", DATA_DIR)
# Return conversation
return conversation
def create_conversation_storage() -> str:
# Generate conversation id
conversation_id = str(uuid.uuid4())
# Save to local
save_to_local([], f"{conversation_id}.json", False, DATA_DIR)
# Return conversation id
return conversation_id
def update_conversation_storage(id: str, role: str, message: str) -> list:
# Get conversation
conversation = get_conversation_storage(id)
# Append new message
conversation.append({
"role": role,
"content": message
})
# Save to local
save_to_local(conversation, f"{id}.json", False, DATA_DIR)
# Return conversation
return conversation
def delete_conversation_storage(id: str):
# Delete conversation
remove_from_local(f"{id}.json", DATA_DIR)
|