Skip to content

Commit

Permalink
Formatting fix.
Browse files Browse the repository at this point in the history
Also update checks.sh to use the same command as CI, locking the ruff version
  • Loading branch information
scosman committed Jan 9, 2025
1 parent 6e7384e commit f121ce4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ headerEnd=" ===\033[0m\n"

echo "${headerStart}Checking Python: Ruff, format, check${headerEnd}"
# I is import sorting
ruff check --select I
ruff format --check
uvx ruff check --select I
uvx ruff format --check .

echo "${headerStart}Checking for Misspellings${headerEnd}"
find . -type f | grep -v "/node_modules/" | grep -v "/\." | grep -v "/dist/" | grep -v "/desktop/build/" | xargs misspell -error
Expand Down
10 changes: 5 additions & 5 deletions libs/core/kiln_ai/adapters/prompt_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def build_prompt(self) -> str:
)
# iterate requirements, formatting them in numbereed list like 1) task.instruction\n2)...
for i, requirement in enumerate(self.task.requirements):
base_prompt += f"{i+1}) {requirement.instruction}\n"
base_prompt += f"{i + 1}) {requirement.instruction}\n"

return base_prompt

Expand All @@ -126,12 +126,12 @@ def build_prompt(self) -> str:
Returns:
str: The constructed prompt string with examples.
"""
base_prompt = f"# Instruction\n\n{ self.task.instruction }\n\n"
base_prompt = f"# Instruction\n\n{self.task.instruction}\n\n"

if len(self.task.requirements) > 0:
base_prompt += "# Requirements\n\nYour response should respect the following requirements:\n"
for i, requirement in enumerate(self.task.requirements):
base_prompt += f"{i+1}) {requirement.instruction}\n"
base_prompt += f"{i + 1}) {requirement.instruction}\n"
base_prompt += "\n"

valid_examples = self.collect_examples()
Expand All @@ -148,7 +148,7 @@ def build_prompt(self) -> str:
def prompt_section_for_example(self, index: int, example: TaskRun) -> str:
# Prefer repaired output if it exists, otherwise use the regular output
output = example.repaired_output or example.output
return f"## Example {index+1}\n\nInput: {example.input}\nOutput: {output.output}\n\n"
return f"## Example {index + 1}\n\nInput: {example.input}\nOutput: {output.output}\n\n"

def collect_examples(self) -> list[TaskRun]:
valid_examples: list[TaskRun] = []
Expand Down Expand Up @@ -206,7 +206,7 @@ def prompt_section_for_example(self, index: int, example: TaskRun) -> str:
):
return super().prompt_section_for_example(index, example)

prompt_section = f"## Example {index+1}\n\nInput: {example.input}\n\n"
prompt_section = f"## Example {index + 1}\n\nInput: {example.input}\n\n"
prompt_section += (
f"Initial Output Which Was Insufficient: {example.output.output}\n\n"
)
Expand Down
9 changes: 6 additions & 3 deletions libs/core/kiln_ai/adapters/test_prompt_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ def test_few_shot_prompt_builder(tmp_path):
# Create 6 examples (2 repaired, 4 high-quality)
for i in range(6):
run = TaskRun(
input=f'{{"subject": "Subject {i+1}"}}',
input=f'{{"subject": "Subject {i + 1}"}}',
input_source=DataSource(
type=DataSourceType.human,
properties={"created_by": "john_doe"},
),
parent=task,
output=TaskOutput(
output=f'{{"joke": "Joke Initial Output {i+1}"}}',
output=f'{{"joke": "Joke Initial Output {i + 1}"}}',
source=DataSource(
type=DataSourceType.human,
properties={"created_by": "john_doe"},
Expand All @@ -262,7 +262,7 @@ def test_few_shot_prompt_builder(tmp_path):
update={
"repair_instructions": "Fix the joke",
"repaired_output": TaskOutput(
output=f'{{"joke": "Repaired Joke {i+1}"}}',
output=f'{{"joke": "Repaired Joke {i + 1}"}}',
source=DataSource(
type=DataSourceType.human,
properties={"created_by": "jane_doe"},
Expand Down Expand Up @@ -335,6 +335,9 @@ def test_prompt_builder_from_ui_name(task_with_examples):
with pytest.raises(ValueError, match="Unknown prompt builder: invalid_name"):
prompt_builder_from_ui_name("invalid_name", task)

with pytest.raises(ValueError, match="Prompt ID not found: 123"):
prompt_builder_from_ui_name("id::123", task)


def test_example_count():
assert FewShotPromptBuilder.example_count() == 4
Expand Down
12 changes: 6 additions & 6 deletions libs/server/kiln_server/test_run_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ async def test_update_run(client, tmp_path):
json=case["updates"],
)

assert (
response.status_code == case["expected_status"]
), f"Failed on case: {case['name']}"
assert (
response.json()["message"] == case["expected_detail"]
), f"Failed on case: {case['name']}"
assert response.status_code == case["expected_status"], (
f"Failed on case: {case['name']}"
)
assert response.json()["message"] == case["expected_detail"], (
f"Failed on case: {case['name']}"
)


@pytest.fixture
Expand Down

0 comments on commit f121ce4

Please sign in to comment.