enh: get_last_user_message_item

This commit is contained in:
Timothy J. Baek 2024-07-02 00:37:21 -07:00
parent fefa8a81d0
commit 7725a877d6

View File

@ -8,14 +8,22 @@ import uuid
import time
def get_last_user_message(messages: List[dict]) -> str:
def get_last_user_message_item(messages: List[dict]) -> str:
for message in reversed(messages):
if message["role"] == "user":
if isinstance(message["content"], list):
for item in message["content"]:
if item["type"] == "text":
return item["text"]
return message["content"]
return message
return None
def get_last_user_message(messages: List[dict]) -> str:
message = get_last_user_message_item(messages)
if message is not None:
if isinstance(message["content"], list):
for item in message["content"]:
if item["type"] == "text":
return item["text"]
return message["content"]
return None