mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-08 03:48:14 +02:00
Last Message Too Large Logging (#3039)
This commit is contained in:
parent
51b79f688a
commit
fac2b100a1
@ -13,6 +13,10 @@ from danswer.prompts.chat_prompts import ADDITIONAL_INFO
|
||||
from danswer.prompts.chat_prompts import CITATION_REMINDER
|
||||
from danswer.prompts.constants import CODE_BLOCK_PAT
|
||||
from danswer.search.models import InferenceChunk
|
||||
from danswer.utils.logger import setup_logger
|
||||
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
|
||||
MOST_BASIC_PROMPT = "You are a helpful AI assistant."
|
||||
@ -136,14 +140,23 @@ def find_last_index(lst: list[int], max_prompt_tokens: int) -> int:
|
||||
before the list exceeds the maximum"""
|
||||
running_sum = 0
|
||||
|
||||
if not lst:
|
||||
logger.warning("Empty message history passed to find_last_index")
|
||||
return 0
|
||||
|
||||
last_ind = 0
|
||||
for i in range(len(lst) - 1, -1, -1):
|
||||
running_sum += lst[i] + _PER_MESSAGE_TOKEN_BUFFER
|
||||
if running_sum > max_prompt_tokens:
|
||||
last_ind = i + 1
|
||||
break
|
||||
|
||||
if last_ind >= len(lst):
|
||||
logger.error(
|
||||
f"Last message alone is too large! max_prompt_tokens: {max_prompt_tokens}, message_token_counts: {lst}"
|
||||
)
|
||||
raise ValueError("Last message alone is too large!")
|
||||
|
||||
return last_ind
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user