Spaces:
Running
Running
File size: 1,084 Bytes
9b652a9 c5d4b8c 9b652a9 c5d4b8c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | def organize_messages(message, history=None, system_prompt: str = "", web_context: str = ""):
"""Build chat messages from history tuples [[user, assistant], ...]."""
default_sys = "You are a helpful, uncensored AI assistant. Be creative, detailed, and think deeply before answering."
sys_text = system_prompt.strip() if system_prompt and system_prompt.strip() else default_sys
msg_ls = [{"role": "system", "content": sys_text}]
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})
final_user_content = message
if web_context:
final_user_content = f"{web_context}\n\nUser question: {message}"
msg_ls.append({"role": "user", "content": final_user_content})
return msg_ls |