4 ms·
In your loop: for m in reversed(self.messages): if total_tokens + m.length <= max_tokens: recent_messages_rever
by upwardbound 3y ago
In your loop:
for m in reversed(self.messages):
if total_tokens + m.length <= max_tokens:
recent_messages_reversed.append({
"role": m.role,
"content": m.text
})
total_tokens += m.length
else:
break
It would be important to change that to not drop system prompts, ever. Otherwise a user can defeat the system prompt simply by providing enough user messages.
- ilaksh 3y agoGood point. The way I use it though is to always add the system prompt to the front after calling that function.