Spaces:
Running
Running
| # | |
| # 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 |