Check if the messages will fit within the model's token limits.
(self, messages)
| 1394 | return chunks |
| 1395 | |
| 1396 | def check_tokens(self, messages): |
| 1397 | """Check if the messages will fit within the model's token limits.""" |
| 1398 | input_tokens = self.main_model.token_count(messages) |
| 1399 | max_input_tokens = self.main_model.info.get("max_input_tokens") or 0 |
| 1400 | |
| 1401 | if max_input_tokens and input_tokens >= max_input_tokens: |
| 1402 | self.io.tool_error( |
| 1403 | f"Your estimated chat context of {input_tokens:,} tokens exceeds the" |
| 1404 | f" {max_input_tokens:,} token limit for {self.main_model.name}!" |
| 1405 | ) |
| 1406 | self.io.tool_output("To reduce the chat context:") |
| 1407 | self.io.tool_output("- Use /drop to remove unneeded files from the chat") |
| 1408 | self.io.tool_output("- Use /clear to clear the chat history") |
| 1409 | self.io.tool_output("- Break your code into smaller files") |
| 1410 | self.io.tool_output( |
| 1411 | "It's probably safe to try and send the request, most providers won't charge if" |
| 1412 | " the context limit is exceeded." |
| 1413 | ) |
| 1414 | |
| 1415 | if not self.io.confirm_ask("Try to proceed anyway?"): |
| 1416 | return False |
| 1417 | return True |
| 1418 | |
| 1419 | def send_message(self, inp): |
| 1420 | self.event("message_send_starting") |
no test coverage detected