Skip to content

Commit

Permalink
Prompt builder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scosman committed Sep 10, 2024
1 parent ce6fac4 commit 174076e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions libs/core/kiln_ai/adapters/test_prompt_builders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from kiln_ai.adapters.base_adapter import BaseAdapter
from kiln_ai.adapters.prompt_builders import SimplePromptBuilder
from kiln_ai.adapters.test_prompt_adaptors import build_test_task
from kiln_ai.adapters.test_structured_output import build_structured_output_test_task


def test_simple_prompt_builder(tmp_path):
task = build_test_task(tmp_path)
builder = SimplePromptBuilder(task=task)
input = "two plus two"
prompt = builder.build_prompt(input)
assert (
"You are an assistant which performs math tasks provided in plain text."
in prompt
)

# TODO this should be a user message later
assert input in prompt

assert "1) " + task.requirements()[0].instruction in prompt
assert "2) " + task.requirements()[1].instruction in prompt
assert "3) " + task.requirements()[2].instruction in prompt


class MockAdapter(BaseAdapter):
def adapter_specific_instructions(self) -> str | None:
return "You are a mock, send me the response!"

def _run(self, input: str) -> str:
return "mock response"


def test_simple_prompt_builder_structured_output(tmp_path):
task = build_structured_output_test_task(tmp_path)
builder = SimplePromptBuilder(task=task)
builder.adapter = MockAdapter(task)
input = "Cows"
prompt = builder.build_prompt(input)
assert "You are an assistant which tells a joke, given a subject." in prompt

# TODO this should be a user message later
assert input in prompt

# check adapter instructions are included
assert "You are a mock, send me the response!" in prompt

0 comments on commit 174076e

Please sign in to comment.