Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Langsmith is incorrectly tracing tokens

$
0
0

I have a simple langgraph chain in place and I noticed that the counting of tokens is oddly off in langsmith in comperison to OpenAI online tokenizer or Python tokenizer:

Langsmith tokens (2,067):enter image description here

Python program:

import tiktokendef num_tokens_from_string(string: str) -> int:    encoding = tiktoken.get_encoding("cl100k_base")    num_tokens = len(encoding.encode(string))    return num_tokenstest_string = """ Ctrl+c ctrl+v from langsmith trace """print(num_tokens_from_string(test_string))

Output:11185

OpenAI tokenizer:enter image description here

Question:

  1. Why are the token counts different for langsmith and OpenAI?
  2. How do I send / set in Langsmith correct counting token methods? For this python code: response = ChatOpenAI().invoke("Hello!")

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>