Skip to content

vertexai: Added ChatVertexAI test case with configurable_fields for thinking_budget #926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions libs/vertexai/tests/integration_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
SystemMessagePromptTemplate,
)
from langchain_core.rate_limiters import InMemoryRateLimiter
from langchain_core.runnables import RunnableSerializable
from langchain_core.runnables import ConfigurableField, RunnableSerializable
from langchain_core.tools import tool
from pydantic import BaseModel, Field
from typing_extensions import TypedDict
Expand Down Expand Up @@ -825,7 +825,25 @@ def test_chat_vertexai_gemini_thinking() -> None:
@pytest.mark.release
def test_chat_vertexai_gemini_thinking_disabled() -> None:
model = ChatVertexAI(model_name=_DEFAULT_THINKING_MODEL_NAME, thinking_budget=0)
response = model.invoke([HumanMessage("How many O's are in Google?")])
response = model.invoke("How many O's are in Google?")
assert isinstance(response, AIMessage)
assert (
response.usage_metadata["total_tokens"] # type: ignore
== response.usage_metadata["input_tokens"] # type: ignore
+ response.usage_metadata["output_tokens"] # type: ignore
)
assert "output_token_details" not in response.usage_metadata # type: ignore


@pytest.mark.release
def test_chat_vertexai_gemini_thinking_configurable() -> None:
model = ChatVertexAI(model_name=_DEFAULT_THINKING_MODEL_NAME)
configurable_model = model.configurable_fields(
thinking_budget=ConfigurableField(id="thinking_budget")
)
response = configurable_model.invoke(
"How many O's are in Google?", {"configurable": {"thinking_budget": 0}}
)
assert isinstance(response, AIMessage)
assert (
response.usage_metadata["total_tokens"] # type: ignore
Expand Down