Added conversation history (#4)
Reviewed-on: #4 Co-authored-by: Ryan Chen <ryan@torrtle.co> Co-committed-by: Ryan Chen <ryan@torrtle.co>
This commit was merged in pull request #4.
This commit is contained in:
32
blueprints/conversation/logic.py
Normal file
32
blueprints/conversation/logic.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from .models import Conversation, ConversationMessage
|
||||
|
||||
|
||||
async def create_conversation(name: str = "") -> Conversation:
|
||||
conversation = await Conversation.create(name=name)
|
||||
return conversation
|
||||
|
||||
|
||||
async def add_message_to_conversation(
|
||||
conversation: Conversation,
|
||||
message: str,
|
||||
speaker: str,
|
||||
) -> ConversationMessage:
|
||||
print(conversation, message, speaker)
|
||||
message = await ConversationMessage.create(
|
||||
text=message,
|
||||
speaker=speaker,
|
||||
conversation=conversation,
|
||||
)
|
||||
|
||||
return message
|
||||
|
||||
|
||||
async def get_the_only_conversation() -> Conversation:
|
||||
try:
|
||||
conversation = await Conversation.all().first()
|
||||
if conversation is None:
|
||||
conversation = await Conversation.create(name="simba_chat")
|
||||
except Exception as _e:
|
||||
conversation = await Conversation.create(name="simba_chat")
|
||||
|
||||
return conversation
|
||||
Reference in New Issue
Block a user