Skip to content
Merged
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
7 changes: 7 additions & 0 deletions docs/release-notes/v2.2.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Release v2.2.2
### What's changed

#### Added features:
* further stabilize prompt handling

**Full Changelog**: [here](https://github.com/finitearth/promptolution/compare/2.2.1...v2.2.2)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ nav:
- Home: index.md
- Release Notes:
- Overview: release-notes.md
- v2.2.2: release-notes/v2.2.2.md
- v2.2.1: release-notes/v2.2.1.md
- v2.2.0: release-notes/v2.2.0.md
- v2.1.0: release-notes/v2.1.0.md
Expand Down
17 changes: 12 additions & 5 deletions promptolution/optimizers/base_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ def __init__(
config (ExperimentConfig, optional): Configuration for the optimizer, overriding defaults.
"""
# Set up optimizer state
self.prompts: List[Prompt] = [Prompt(p) for p in initial_prompts] if initial_prompts else []
if config is not None:
config.apply_to(self)

if initial_prompts is None and config is not None and config.prompts is not None:
initial_prompts = config.prompts

assert initial_prompts is not None, "Initial prompts must be provided either directly or through the config."
if isinstance(initial_prompts[0], str):
self.prompts = [Prompt(p) for p in initial_prompts]
else:
self.prompts = initial_prompts

if task.task_type == "multi" and not self.supports_multi_objective:
logger.warning(
f"{self.__class__.__name__} does not support multi-objective tasks, objectives will be averaged equally.",
Expand All @@ -62,10 +73,6 @@ def __init__(
self.callbacks: List["BaseCallback"] = callbacks or []
self.predictor = predictor
self.scores: List[float] = []

if config is not None:
config.apply_to(self)

self.config = config

def optimize(self, n_steps: int) -> List[Prompt]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "promptolution"
version = "2.2.1"
version = "2.2.2"
description = "A framework for prompt optimization and a zoo of prompt optimization algorithms."
authors = ["Tom Zehle, Moritz Schlager, Timo Heiß"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def test_get_task_variants(sample_df):
def test_get_optimizer_variants():
pred = MockPredictor(llm=MockLLM())
task = MockTask()
cfg = ExperimentConfig()
cfg = ExperimentConfig(prompts=[Prompt("p1"), Prompt("p2")])

opt = get_optimizer(pred, MockLLM(), task, optimizer="capo", config=cfg)

Expand Down
4 changes: 3 additions & 1 deletion tests/tasks/test_multi_objective_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ def test_multi_objective_fallback_warns_and_averages(caplog):
t2 = ConstantTask(df.copy(), value=3.0)
mo_task = MultiObjectiveTask([t1, t2])

dummy_prompts = [Prompt("p")]

predictor = MockPredictor(llm=MockLLM(predetermined_responses=["p1", "p2"]))

with caplog.at_level("WARNING"):
DummyOptimizer(predictor=predictor, task=mo_task)
DummyOptimizer(predictor=predictor, task=mo_task, initial_prompts=dummy_prompts)

assert mo_task._scalarized_objective is True
assert any("averaged equally" in message for message in caplog.messages)
Expand Down
Loading