-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: ValueError: Usage object must have either {input, output, total, unit} or {promptTokens, completionTokens, totalTokens} #1249
Comments
@pavelm10 thanks for raising this issue! Does it only happen with "some-instruct-model-name"? Which model exactly are you using? |
I am trying to reproduce the issue here: https://github.com/langfuse/langfuse-python/pull/413/files |
@maxdeichmann I am using |
@maxdeichmann I tried your test and it indeed does not generate the traceback. However, our usecase is providing list of inputs to
|
Thanks for the clarification. This helped me to reproduce. I will ship a fix shortly |
@pavelm10 this is an issue by Langchain, but i added a workaround on our end to ensure tokens are correct for total LLM chains. You will see the total sum of tokens on the first Generation in Langfuse, all succeeding ones will have 0 tokens. Background: |
@maxdeichmann I believe I am running into the same issue. I tracked it down to https://github.com/langfuse/langfuse-python/blame/main/langfuse/utils/__init__.py#L55 . In particular, the object we are passing in from langchain/openAI is such that if you ran |
Ok do you have more details of that such as a screenshot? I get an empty object from langchain before even putting it into langfuse and the code line you were sharing. |
@istandleet this release should fix your issue. Let me know, when you run into issues. Regarding the tokenisation, please create an issue at Langchain. Unfortunately, they only send tokens on the first generation. |
@maxdeichmann thanks for quick fix on your end. |
@maxdeichmann i am still facing this issue. as @istandleet pointed out, at this point calling |
Describe the bug
When using langfuse callback handler for
from langchain_openai import OpenAI
class the tracking fails. When usingfrom langchain_openai import ChatOpenAI
tracking works.traceback:
To reproduce
How we use it
Is the error expected because we are using langfuse wrongly with OpenAI class? Please note we cannot use in our use case
ChatOpenAI
class as we want to use instruct model.Additional information
python 3.11
poetry 1.7.1
langfuse 2.16.2
langchain 0.1.9
langchain-openai 0.0.6
The text was updated successfully, but these errors were encountered: