Merge branch 'geekan:main' into main

This commit is contained in:
krylo 2023-08-29 10:26:42 -05:00 committed by GitHub
commit 1f469d55b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 284 additions and 137 deletions

View file

@ -96,7 +96,7 @@ def count_string_tokens(string: str, model_name: str) -> int:
return len(encoding.encode(string))
def get_max_completion_tokens(messages: list[dict], model: str, default: int) -> int:
def get_max_completion_tokens(messages: list[dict], model: str, default: int) -> int:
"""Calculate the maximum number of completion tokens for a given model and list of messages.
Args:
@ -108,4 +108,4 @@ def get_max_completion_tokens(messages: list[dict], model: str, default: int) ->
"""
if model not in TOKEN_MAX:
return default
return TOKEN_MAX[model] - count_message_tokens(messages)
return TOKEN_MAX[model] - count_message_tokens(messages) - 1