Home / Function/ test_count_tokens_approximately_openai_format() — langchain Function Reference

test_count_tokens_approximately_openai_format() — langchain Function Reference

Architecture documentation for the test_count_tokens_approximately_openai_format() function in test_utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  a0d4342d_bf50_4d26_a09a_027613ff8ad1["test_count_tokens_approximately_openai_format()"]
  ea3f8d89_f44b_6738_3cb9_a740a73cfca4["test_utils.py"]
  a0d4342d_bf50_4d26_a09a_027613ff8ad1 -->|defined in| ea3f8d89_f44b_6738_3cb9_a740a73cfca4
  style a0d4342d_bf50_4d26_a09a_027613ff8ad1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/messages/test_utils.py lines 1498–1509

def test_count_tokens_approximately_openai_format() -> None:
    # same as test_count_tokens_approximately_with_names, but in OpenAI format
    messages = [
        {"role": "user", "content": "Hello", "name": "user"},
        {"role": "assistant", "content": "Hi there", "name": "assistant"},
    ]
    # With names included (default)
    assert count_tokens_approximately(messages) == 17

    # Without names
    without_names = count_tokens_approximately(messages, count_name=False)
    assert without_names == 14

Subdomains

Frequently Asked Questions

What does test_count_tokens_approximately_openai_format() do?
test_count_tokens_approximately_openai_format() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/messages/test_utils.py.
Where is test_count_tokens_approximately_openai_format() defined?
test_count_tokens_approximately_openai_format() is defined in libs/core/tests/unit_tests/messages/test_utils.py at line 1498.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free