File size: 698 Bytes
d70f24f
 
b21e239
d70f24f
 
 
 
 
 
 
 
 
 
b21e239
2a3fb06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def organize_messages(message, history=None):
    """Build chat messages from history tuples [[user, assistant], ...]."""
    msg_ls = [{"role": "system", "content": "You are a helpful assistant."}]
    if history:
        for turn in history:
            if not turn:
                continue
            user_text = turn[0] if len(turn) > 0 else None
            assistant_text = turn[1] if len(turn) > 1 else None
            if user_text:
                msg_ls.append({"role": "user", "content": user_text})
            if assistant_text:
                msg_ls.append({"role": "assistant", "content": assistant_text})
    msg_ls.append({"role": "user", "content": message})
    return msg_ls