Skip to content

Commit 75d05c5

Browse files
authored
vertexai: Added ChatVertexAI test case with configurable_fields for thinking_budget (#926)
1 parent 58046e8 commit 75d05c5

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

libs/vertexai/tests/integration_tests/test_chat_models.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
SystemMessagePromptTemplate,
3030
)
3131
from langchain_core.rate_limiters import InMemoryRateLimiter
32-
from langchain_core.runnables import RunnableSerializable
32+
from langchain_core.runnables import ConfigurableField, RunnableSerializable
3333
from langchain_core.tools import tool
3434
from pydantic import BaseModel, Field
3535
from typing_extensions import TypedDict
@@ -980,13 +980,25 @@ def get_weather(location: str) -> str:
980980

981981
@pytest.mark.release
982982
def test_chat_vertexai_gemini_thinking_disabled() -> None:
983-
model = ChatVertexAI(
984-
model_name=_DEFAULT_THINKING_MODEL_NAME,
985-
thinking_budget=200, # Test we override with runtime kwarg
983+
model = ChatVertexAI(model_name=_DEFAULT_THINKING_MODEL_NAME, thinking_budget=0)
984+
response = model.invoke("How many O's are in Google?")
985+
assert isinstance(response, AIMessage)
986+
assert (
987+
response.usage_metadata["total_tokens"] # type: ignore
988+
== response.usage_metadata["input_tokens"] # type: ignore
989+
+ response.usage_metadata["output_tokens"] # type: ignore
986990
)
987-
response = model.invoke(
988-
[HumanMessage("How many O's are in Google?")],
989-
thinking_budget=0, # Disable thinking
991+
assert "output_token_details" not in response.usage_metadata # type: ignore
992+
993+
994+
@pytest.mark.release
995+
def test_chat_vertexai_gemini_thinking_configurable() -> None:
996+
model = ChatVertexAI(model_name=_DEFAULT_THINKING_MODEL_NAME)
997+
configurable_model = model.configurable_fields(
998+
thinking_budget=ConfigurableField(id="thinking_budget")
999+
)
1000+
response = configurable_model.invoke(
1001+
"How many O's are in Google?", {"configurable": {"thinking_budget": 0}}
9901002
)
9911003
assert isinstance(response, AIMessage)
9921004
assert response.usage_metadata is not None

0 commit comments

Comments
 (0)