update get_num_tokens_from_messages model (#8431)

(#8430)

Co-authored-by: Kano Kunihiko <kkano@heroz.co.jp>
This commit is contained in:
lvisdd 2023-07-29 07:07:03 +09:00 committed by GitHub
parent e0de62f6da
commit abe4c361f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -550,12 +550,12 @@ class ChatOpenAI(BaseChatModel):
if sys.version_info[1] <= 7:
return super().get_num_tokens_from_messages(messages)
model, encoding = self._get_encoding_model()
if model.startswith("gpt-3.5-turbo"):
if model.startswith("gpt-3.5-turbo-0301"):
# every message follows <im_start>{role/name}\n{content}<im_end>\n
tokens_per_message = 4
# if there's a name, the role is omitted
tokens_per_name = -1
elif model.startswith("gpt-4"):
elif model.startswith("gpt-3.5-turbo") or model.startswith("gpt-4"):
tokens_per_message = 3
tokens_per_name = 1
else: