How to get token information(response_metadata) from the result in stream #25944
Unanswered
JANGSOONMYUN
asked this question in
Q&A
Replies: 1 comment 6 replies
-
To get token information ( import sys
# Assuming chat is an instance of ChatBaichuan
messages = [
("system", "You are a helpful assistant."),
("human", "Tell me a joke."),
]
for chunk in chat.stream(messages):
sys.stdout.write(chunk.message.content)
sys.stdout.flush()
print(chunk.message.response_metadata) In this example, |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I would like to know how to get correct token information after getting the result via streaming.
If the result without streaming, it includes response_metadata but if with streaming, it doesn't have response_metadata.
I want to check the currently used token size when I use stream option.
System Info
langchain==0.2.9
langchain-community==0.2.9
langchain-core==0.2.22
langchain-openai==0.1.10
langchain-text-splitters==0.2.2
langchainhub==0.1.21
linux(ubuntu)
python 3.9
Beta Was this translation helpful? Give feedback.
All reactions