Skip to content

Commit 3f46cf7

Browse files
authored
Add sensible defaults (#140)
* add sensible defaults * update lockfile * update tests * fix bound value in lambda
1 parent 7fb7fb1 commit 3f46cf7

File tree

7 files changed

+19
-9
lines changed

7 files changed

+19
-9
lines changed

patchwork/common/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from chromadb.api.types import Documents, EmbeddingFunction
99
from chromadb.utils import embedding_functions
1010
from git import Head, Repo
11-
from typing_extensions import Callable
11+
from typing_extensions import Callable, TypedDict
1212

1313
from patchwork.managed_files import HOME_FOLDER
1414

@@ -162,3 +162,7 @@ def get_current_branch(repo: Repo) -> Head:
162162
)
163163

164164
return from_branch
165+
166+
167+
def get_required_keys(cls: TypedDict) -> set:
168+
return getattr(cls, "__required_keys__", set())

patchwork/steps/CommitChanges/CommitChanges.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __init__(self, inputs: dict):
122122
self.enabled = False
123123

124124
self.force = inputs.get("force_branch_creation", True)
125-
self.branch_prefix = inputs.get("branch_prefix", "")
125+
self.branch_prefix = inputs.get("branch_prefix", "patchwork-")
126126
self.branch_suffix = inputs.get("branch_suffix", "")
127127
if self.enabled and self.branch_prefix == "" and self.branch_suffix == "":
128128
raise ValueError("Both branch_prefix and branch_suffix cannot be empty")

patchwork/steps/ExtractModelResponse/ExtractModelResponse.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ def __init__(self, inputs: dict):
1818

1919
def run(self) -> dict:
2020
if len(self.partitions) <= 0:
21-
logger.error("No partitions specified for model response. Exiting.")
22-
return dict(extracted_responses=[])
21+
outputs = []
22+
for openai_response in self.openai_responses:
23+
output = defaultdict(lambda bound_value=openai_response: bound_value)
24+
outputs.append(output)
25+
logger.error("No partitions specified for model response. defaulting.")
26+
return dict(extracted_responses=outputs)
2327

2428
outputs = []
2529
for openai_response in self.openai_responses:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing_extensions import Iterable, NotRequired, TypedDict
22

33

4-
class ExtractModelResponsesInputs(TypedDict):
4+
class ExtractModelResponseInputs(TypedDict):
55
openai_responses: Iterable[str]
66
response_partitions: NotRequired[dict[str, list[str]]]
77

88

9-
class ExtractModelResponsesOutputs(TypedDict):
9+
class ExtractModelResponseOutputs(TypedDict):
1010
extracted_responses: list[dict[str, str]]

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "patchwork-cli"
3-
version = "0.0.13"
3+
version = "0.0.14"
44
description = ""
55
authors = ["patched.codes"]
66
license = "AGPL"

tests/steps/test_ExtractModelResponse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def test_init_missing_required_keys():
2727
def test_run_no_partitions(sample_inputs):
2828
step = ExtractModelResponse({**sample_inputs, "response_partitions": {}})
2929
output = step.run()
30-
assert output == {"extracted_responses": []}
30+
assert len(output["extracted_responses"]) == 2
31+
assert output["extracted_responses"][0]["anyKeyHere"] == "partition1response1partition2"
32+
assert output["extracted_responses"][1]["kEy"] == "response2partition3"
3133

3234

3335
def test_run_with_partitions(sample_inputs):

0 commit comments

Comments
 (0)