mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
Use max_input_token
for trim_messages
This commit is contained in:
parent
7ffd3d40fa
commit
ebc889d77a
2 changed files with 24 additions and 5 deletions
|
@ -10577,16 +10577,19 @@ def trim_messages(
|
|||
messages = copy.deepcopy(messages)
|
||||
try:
|
||||
print_verbose(f"trimming messages")
|
||||
if max_tokens == None:
|
||||
if max_tokens is None:
|
||||
# Check if model is valid
|
||||
if model in litellm.model_cost:
|
||||
max_tokens_for_model = litellm.model_cost[model]["max_tokens"]
|
||||
if (
|
||||
model in litellm.model_cost
|
||||
and "max_input_tokens" in litellm.model_cost[model]
|
||||
):
|
||||
max_tokens_for_model = litellm.model_cost[model]["max_input_tokens"]
|
||||
max_tokens = int(max_tokens_for_model * trim_ratio)
|
||||
else:
|
||||
# if user did not specify max tokens
|
||||
# if user did not specify max input tokens
|
||||
# or passed an llm litellm does not know
|
||||
# do nothing, just return messages
|
||||
return
|
||||
return messages
|
||||
|
||||
system_message = ""
|
||||
for message in messages:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue