Spaces:
Runtime error
Runtime error
Download utils_chatbot.py from Easyfly/MiniCPM5-1B-Demo: direct link, hf CLI and curl.
- Browser
- Download file 698 Bytes
-
https://huggingface.co/spaces/Easyfly/MiniCPM5-1B-Demo/resolve/main/utils_chatbot.py
- Command line
-
hf download hf://spaces/Easyfly/MiniCPM5-1B-Demo/utils_chatbot.py
-
curl -L -o utils_chatbot.py https://huggingface.co/spaces/Easyfly/MiniCPM5-1B-Demo/resolve/main/utils_chatbot.py
698 Bytes
| 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 | |