File size: 831 Bytes
ceb70c7
 
 
 
 
 
 
 
 
bcca9d9
 
ceb70c7
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#
# SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
# SPDX-License-Identifier: Apache-2.0
#

def setup_response(system_instruction, conversation_history, user_input):
    history = []
    
    if system_instruction:
        history.append({"role": "system", "content": system_instruction})
    
    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