Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ def rewrite_execution_settings(

def add_execution_settings(self, settings: PromptExecutionSettings, overwrite: bool = True) -> None:
"""Add execution settings to the prompt template."""
if settings.service_id in self.execution_settings and not overwrite:
# Check existence with the same key that storage uses: when service_id is None the settings are
# stored under DEFAULT_SERVICE_NAME, so testing service_id (None) never matches and overwrite=False
# silently has no effect (see issue #14582).
key = settings.service_id or DEFAULT_SERVICE_NAME
if key in self.execution_settings and not overwrite:
logger.warning("Execution settings already exist and overwrite is set to False")
return
self.execution_settings[settings.service_id or DEFAULT_SERVICE_NAME] = settings
logger.warning("Execution settings already exist and overwrite is set to False")
self.execution_settings[key] = settings

def get_kernel_parameter_metadata(self) -> Sequence[KernelParameterMetadata]:
"""Get the kernel parameter metadata for the input variables."""
Expand Down
27 changes: 27 additions & 0 deletions python/tests/unit/prompt_template/test_prompt_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import json
import logging

import yaml
from pytest import raises
Expand Down Expand Up @@ -72,6 +73,32 @@ def test_add_execution_settings_with_overwrite():
assert config.execution_settings["test"].extension_data["setting_value"] == "new_value2"


def test_add_execution_settings_no_overwrite_default_service():
"""overwrite=False protects the entry stored under DEFAULT_SERVICE_NAME (service_id is None)."""
config = PromptTemplateConfig(template="Example template")
first = PromptExecutionSettings(extension_data={"temperature": 0.1})
config.add_execution_settings(first)
assert config.execution_settings["default"] == first

second = PromptExecutionSettings(extension_data={"temperature": 0.9})
config.add_execution_settings(second, overwrite=False)
assert config.execution_settings["default"].extension_data["temperature"] == 0.1


def test_add_execution_settings_warning_only_when_refused(caplog):
"""The "already exists" warning is emitted only when an add is refused, not after every add."""
with caplog.at_level(logging.WARNING):
config = PromptTemplateConfig(template="Example template")
settings = PromptExecutionSettings(extension_data={"temperature": 0.1})
config.add_execution_settings(settings, overwrite=False)
assert "overwrite is set to False" not in caplog.text

caplog.clear()
other = PromptExecutionSettings(extension_data={"temperature": 0.9})
config.add_execution_settings(other, overwrite=False)
assert "overwrite is set to False" in caplog.text


def test_get_kernel_parameter_metadata_empty():
config = PromptTemplateConfig(template="Example template")
metadata = config.get_kernel_parameter_metadata()
Expand Down
Loading