File size: 1,028 Bytes
ceb70c7
 
 
 
 
29dc222
 
 
 
ceb70c7
29dc222
 
 
 
 
 
 
 
 
 
 
 
bcca9d9
ceb70c7
 
 
 
 
 
 
 
 
 
 
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
#
# 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