test_prediction_tokens() — langchain Function Reference
Architecture documentation for the test_prediction_tokens() function in test_base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 76cb5eeb_804b_66dd_6905_0c38a9bc0d83["test_prediction_tokens()"] bd382a4e_442c_13ae_530c_6e34bc43623d["test_base.py"] 76cb5eeb_804b_66dd_6905_0c38a9bc0d83 -->|defined in| bd382a4e_442c_13ae_530c_6e34bc43623d style 76cb5eeb_804b_66dd_6905_0c38a9bc0d83 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/openai/tests/integration_tests/chat_models/test_base.py lines 960–1001
def test_prediction_tokens() -> None:
code = dedent(
"""
/// <summary>
/// Represents a user with a first name, last name, and username.
/// </summary>
public class User
{
/// <summary>
/// Gets or sets the user's first name.
/// </summary>
public string FirstName { get; set; }
/// <summary>
/// Gets or sets the user's last name.
/// </summary>
public string LastName { get; set; }
/// <summary>
/// Gets or sets the user's username.
/// </summary>
public string Username { get; set; }
}
"""
)
llm = ChatOpenAI(model="gpt-4.1-nano")
query = (
"Replace the Username property with an Email property. "
"Respond only with code, and with no markdown formatting."
)
response = llm.invoke(
[{"role": "user", "content": query}, {"role": "user", "content": code}],
prediction={"type": "content", "content": code},
)
assert isinstance(response, AIMessage)
assert response.response_metadata is not None
output_token_details = response.response_metadata["token_usage"][
"completion_tokens_details"
]
assert output_token_details["accepted_prediction_tokens"] > 0
assert output_token_details["rejected_prediction_tokens"] > 0
Domain
Subdomains
Source
Frequently Asked Questions
What does test_prediction_tokens() do?
test_prediction_tokens() is a function in the langchain codebase, defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py.
Where is test_prediction_tokens() defined?
test_prediction_tokens() is defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py at line 960.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free