INNER CODE UNIT · Python
last_assistant_idx
seratch/ChatGPT-in-Slack · app/bolt_listeners.py:377
if is_in_dm_with_bot is True or last_assistant_idx == -1:
# To know whether this app needs to start a new convo
if not next(filter(lambda msg: msg["role"] == "system", messages), None):
# Replace placeholder for Slack user ID in the system prompt
system_text = build_system_text(
SYSTEM_TEXT, TRANSLATE_MARKDOWN, context
)
messages.insert(0, {"role": "system", "content": system_text})
filtered_messages_in_context = []
for idx, reply in enumerate(messages_in_context):
# Strip bot Slack user ID from initial message
if idx == 0:
reply["text"] = re.sub(
f"<@{context.bot_user_id}>\\s*", "", reply["text"]
)
if idx not in indices_to_remove:
filtered_messages_in_context.append(reply)