mirror of
https://github.com/home-assistant/core.git
synced 2026-09-14 04:30:02 +01:00
Fix OpenAI prompt caching (#181472)
This commit is contained in:
@@ -517,6 +517,7 @@ class OpenAIBaseLLMEntity(Entity):
|
||||
input=messages,
|
||||
max_output_tokens=options.get(CONF_MAX_TOKENS, RECOMMENDED_MAX_TOKENS),
|
||||
user=chat_log.conversation_id,
|
||||
prompt_cache_key=self.subentry.subentry_id,
|
||||
service_tier=options.get(CONF_SERVICE_TIER, RECOMMENDED_SERVICE_TIER),
|
||||
store=options.get(CONF_STORE_RESPONSES, RECOMMENDED_STORE_RESPONSES),
|
||||
stream=True,
|
||||
|
||||
@@ -66,6 +66,10 @@ async def test_generate_data(
|
||||
assert result.data == "The test data"
|
||||
assert mock_create_stream.call_args is not None
|
||||
assert mock_create_stream.call_args.kwargs["store"] is expected_store
|
||||
assert (
|
||||
mock_create_stream.call_args.kwargs["prompt_cache_key"]
|
||||
== ai_task_entry.subentry_id
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_init_component")
|
||||
|
||||
@@ -823,13 +823,13 @@ async def test_flex_tier_retry(
|
||||
@pytest.mark.parametrize(
|
||||
"subentry_options", [{CONF_CHAT_MODEL: "gpt-5.6-sol", CONF_PRO_MODE: True}]
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_init_component")
|
||||
async def test_model_args(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_init_component,
|
||||
mock_create_stream: AsyncMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
subentry_options: dict,
|
||||
subentry_options: dict[str, str | bool],
|
||||
) -> None:
|
||||
"""Test model arguments for various configuration."""
|
||||
|
||||
@@ -860,4 +860,5 @@ async def test_model_args(
|
||||
model_args = mock_create_stream.call_args.kwargs.copy()
|
||||
model_args.pop("input")
|
||||
assert model_args.pop("user") == result.conversation_id
|
||||
assert model_args.pop("prompt_cache_key") == subentry.subentry_id
|
||||
assert model_args == snapshot
|
||||
|
||||
Reference in New Issue
Block a user