ChatGPT (model unspecified)· OpenAI
ShareLM (browser-extension contributions)
role = "User" if turn["role"] == "user" else "Assistant" I want to add another option,…
- User
role = "User" if turn["role"] == "user" else "Assistant"
I want to add another option, for role == "system"
- Assistant
You can extend your ternary logic to include "system" using a simple if-elif-else chain. Here's how: pythonCopyEditif turn["role"] == "user": role = "User" elif turn["role"] == "assistant": role = "Assistant" elif turn["role"] == "system": role = "System" else: role = "Unknown"
If you prefer a more concise, dictionary-based approach: pythonCopyEditrole_map = { "user": "User", "assistant": "Assistant", "system": "System" } role = role_map.get(turn["role"], "Unknown")
Let me know which style you prefer or if you want to keep it strictly one-liner.