mirror of
https://github.com/hwchase17/langchain
synced 2024-11-04 06:00:26 +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:
|
||||
num_tokens += tokens_per_message
|
||||
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":
|
||||
num_tokens += tokens_per_name
|
||||
# every reply is primed with <im_start>assistant
|
||||
|
Loading…
Reference in New Issue
Block a user