Spaces:
Running
Running
# | |
# SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org> | |
# SPDX-License-Identifier: Apache-2.0 | |
# | |
from ...utils.time import get_current_time | |
from config import INSTRUCTIONS_START | |
def setup_response(conversation_history, user_input): | |
history = [] | |
history.insert( | |
0, | |
{ | |
"role": "system", | |
"content": ( | |
f"Today is: {get_current_time()}" | |
+ "\n\n\n" | |
+ INSTRUCTIONS_START | |
) | |
} | |
) | |
if isinstance(conversation_history, list): | |
for history_item in conversation_history: | |
message_role = history_item.get("role") | |
message_content = history_item.get("content") | |
if message_role in ("user", "assistant") and isinstance(message_content, str): | |
history.append({"role": message_role, "content": message_content}) | |
if isinstance(user_input, str) and user_input.strip(): | |
history.append({"role": "user", "content": user_input}) | |
return history |