langchain-ai / langsmith-sdk

LangSmith Client SDK Implementations
https://smith.langchain.com/
MIT License
385 stars 71 forks source link

Issue: Some traced runs don't log tokens #832

Closed omrish-Glossai closed 3 weeks ago

omrish-Glossai commented 3 months ago

Hello. I've deployed tracing code to my dev env and noticed some of the traced runs seem to be logged without any token information. When checking the traces, It shows the prompt is full of text as usual and the output is as expected. Any ideas on why such a thing happens?

Adding a photo to show some runs were traced properly while others failed: Screenshot 2024-07-01 113520

Suggestion:

No response

hinthornw commented 3 months ago

Could you share code or a run where this occurs?

omrish-Glossai commented 3 months ago

Upon further inspection, it seems like this happens when the prompt has more than 3 pictures in it. Every time I try running something with more than 3 photos the tokens are zero.

hinthornw commented 2 months ago

Python or JS? Is this logged with LangChain code? Or a custom decorator? Or something else?

What model provider? OpenAI?

omrish-Glossai commented 2 months ago

I am using Python and logging with Langchain code. This occurred both with anthropic's claude and openai's gpt-4o

hinthornw commented 2 months ago

What versions of the LangChain OpenAI and LangChain Anthropic packages are you using? Could you share a minimum code example please?

omrish-Glossai commented 2 months ago

langchain-openai==0.0.8 langchain-anthropic==0.1.15 I can't share my exact code, unfortunately. It is something along the lines of:


    init_key(env=env) # initiate the langsmith API key
    os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
    os.environ["LANGCHAIN_TRACING_V2"] = "true"
    env = env or get_env()
    os.environ["LANGCHAIN_PROJECT"] = env # Setting the project as the current environment 
   ...
   ...
   ...
    chain.invoke(
            {},
            {
                "run_name": "analyze_post",
                "metadata": {
                    ...
                },
            },
        )