langchain
275dcbf6 - docs(core): add clarity to base token counting methods (#33958)

Commit
46 days ago
docs(core): add clarity to base token counting methods (#33958) Wasn't immediately obvious that `get_num_tokens_from_messages` adds additional prefixes to represent user roles in conversation, which adds to the overall token count. ```python from langchain_google_genai import GoogleGenerativeAI llm = GoogleGenerativeAI(model="gemini-2.5-flash") num_tokens = llm.get_num_tokens("Hello, world!") print(f"Number of tokens: {num_tokens}") # Number of tokens: 4 ``` ```python from langchain.messages import HumanMessage messages = [HumanMessage(content="Hello, world!")] num_tokens = llm.get_num_tokens_from_messages(messages) print(f"Number of tokens: {num_tokens}") # Number of tokens: 6 ```
Author
Parents
Loading