mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-22 06:39:52 +00:00
cast to string when measuring token length (#8617)
This commit is contained in:
parent
68113348cc
commit
7c5c0557cb
@ -570,7 +570,9 @@ class ChatOpenAI(BaseChatModel):
|
|||||||
for message in messages_dict:
|
for message in messages_dict:
|
||||||
num_tokens += tokens_per_message
|
num_tokens += tokens_per_message
|
||||||
for key, value in message.items():
|
for key, value in message.items():
|
||||||
num_tokens += len(encoding.encode(value))
|
# Cast str(value) in case the message value is not a string
|
||||||
|
# This occurs with function messages
|
||||||
|
num_tokens += len(encoding.encode(str(value)))
|
||||||
if key == "name":
|
if key == "name":
|
||||||
num_tokens += tokens_per_name
|
num_tokens += tokens_per_name
|
||||||
# every reply is primed with <im_start>assistant
|
# every reply is primed with <im_start>assistant
|
||||||
|
Loading…
Reference in New Issue
Block a user