You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thimows opened this issue
May 17, 2024
· 1 comment
Labels
Ɑ: agentRelated to agents module🤖:bugRelated to a bug, vulnerability, unexpected error with an existing feature🔌: openaiPrimarily related to OpenAI integrations
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
I am sure that this is a bug in LangChain rather than my code.
The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
with get_openai_callback() as cb:
async for event in agent_executor.astream_events(
{
"input": input,
"chat_history": history
},
version="v1",
):
# Do stuff....
print(f"Total Tokens: {cb.total_tokens}")
Output:
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
Total Tokens: 0
The text was updated successfully, but these errors were encountered:
dosubotbot
added
Ɑ: agent
Related to agents module
🔌: openai
Primarily related to OpenAI integrations
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
labels
May 17, 2024
Ɑ: agentRelated to agents module🤖:bugRelated to a bug, vulnerability, unexpected error with an existing feature🔌: openaiPrimarily related to OpenAI integrations
Checked other resources
Example Code
Output:
Error Message and Stack Trace (if applicable)
No response
Description
OpenAI supports returning the token count while streaming: https://community.openai.com/t/usage-stats-now-available-when-using-streaming-with-the-chat-completions-api-or-completions-api/738156
However, this does not seem to work when using Langchain. It only seems to return 0's for agent_executor.astream_events.
This makes it very difficult to get the exact token counts for my agent. Are there any solutions?
System Info
langchain==0.1.16
langchain-community==0.0.38
langchain-core==0.1.52
langchain-experimental==0.0.55
langchain-openai==0.1.7
langchain-text-splitters==0.0.1
langchainhub==0.1.15
Platform: mac
Python version: 3.9.6
The text was updated successfully, but these errors were encountered: