From 04333c948bcd04f54cad6db16403f8006170768e Mon Sep 17 00:00:00 2001 From: Amir Elaguizy Date: Sun, 17 Mar 2024 21:31:06 -0500 Subject: [PATCH] Fixed tests --- tests/test_manual_examples.py | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/tests/test_manual_examples.py b/tests/test_manual_examples.py index ab771af..ac643cd 100644 --- a/tests/test_manual_examples.py +++ b/tests/test_manual_examples.py @@ -1,4 +1,3 @@ -# tests/test_prompt_signature_examples.py import pytest from langdspy.field_descriptors import InputField, OutputField, HintField from langdspy.prompt_strategies import PromptSignature, DefaultPromptStrategy @@ -8,7 +7,6 @@ class TestPromptSignature(PromptSignature): input = InputField(name="input", desc="Input field") output = OutputField(name="output", desc="Output field") hint = HintField(desc="Hint field") - __examples__ = [ ({"input": "Example input 1"}, "Example output 1"), ({"input": "Example input 2"}, "Example output 2"), @@ -16,16 +14,13 @@ class TestPromptSignature(PromptSignature): def test_format_prompt_with_examples_openai(): prompt_runner = PromptRunner(template_class=TestPromptSignature, prompt_strategy=DefaultPromptStrategy) - formatted_prompt = prompt_runner.template._format_openai_prompt( trained_state=None, use_training=True, examples=TestPromptSignature.__examples__, input="Test input" ) - print(formatted_prompt) - assert "💡 Hint field" in formatted_prompt assert "✅input: Input field" in formatted_prompt assert "🔑output: Output field" in formatted_prompt @@ -38,17 +33,15 @@ def test_format_prompt_with_examples_openai(): def test_format_prompt_with_examples_anthropic(): prompt_runner = PromptRunner(template_class=TestPromptSignature, prompt_strategy=DefaultPromptStrategy) - formatted_prompt = prompt_runner.template._format_anthropic_prompt( trained_state=None, use_training=True, examples=TestPromptSignature.__examples__, input="Test input" ) - assert "Hint field" in formatted_prompt - assert ": Input field" in formatted_prompt - assert ": Output field" in formatted_prompt + assert "Input field" in formatted_prompt + assert "Output field" in formatted_prompt assert "Example input 1" in formatted_prompt assert "Example output 1" in formatted_prompt assert "Example input 2" in formatted_prompt @@ -58,14 +51,12 @@ def test_format_prompt_with_examples_anthropic(): def test_format_prompt_without_examples_openai(): prompt_runner = PromptRunner(template_class=TestPromptSignature, prompt_strategy=DefaultPromptStrategy) - formatted_prompt = prompt_runner.template._format_openai_prompt( trained_state=None, use_training=False, examples=[], input="Test input" ) - assert "💡 Hint field" in formatted_prompt assert "✅input: Input field" in formatted_prompt assert "🔑output: Output field" in formatted_prompt @@ -78,17 +69,15 @@ def test_format_prompt_without_examples_openai(): def test_format_prompt_without_examples_anthropic(): prompt_runner = PromptRunner(template_class=TestPromptSignature, prompt_strategy=DefaultPromptStrategy) - formatted_prompt = prompt_runner.template._format_anthropic_prompt( trained_state=None, use_training=False, examples=[], input="Test input" ) - assert "Hint field" in formatted_prompt - assert ": Input field" in formatted_prompt - assert ": Output field" in formatted_prompt + assert "Input field" in formatted_prompt + assert "Output field" in formatted_prompt assert "Test input" in formatted_prompt assert "" in formatted_prompt assert "Example input 1" not in formatted_prompt @@ -102,11 +91,9 @@ class ValidPromptSignature(PromptSignature): input2 = InputField(name="input2", desc="Input field 2") output1 = OutputField(name="output1", desc="Output field 1") output2 = OutputField(name="output2", desc="Output field 2") - __examples__ = [ ({"input1": "Example input 1", "input2": "Example input 2"}, {"output1": "Example output 1", "output2": "Example output 2"}), ] - prompt_runner = PromptRunner(template_class=ValidPromptSignature, prompt_strategy=DefaultPromptStrategy) prompt_runner.template.validate_examples() # Should not raise any exception @@ -114,11 +101,9 @@ def test_validate_examples_invalid_input_field(): class InvalidInputPromptSignature(PromptSignature): input = InputField(name="input", desc="Input field") output = OutputField(name="output", desc="Output field") - __examples__ = [ ({"invalid_input": "Example input"}, "Example output"), ] - with pytest.raises(ValueError, match="Example input field 'invalid_input' not found in input_variables"): PromptRunner(template_class=InvalidInputPromptSignature, prompt_strategy=DefaultPromptStrategy) @@ -126,11 +111,9 @@ def test_validate_examples_invalid_output_field(): class InvalidOutputPromptSignature(PromptSignature): input = InputField(name="input", desc="Input field") output = OutputField(name="output", desc="Output field") - __examples__ = [ ({"input": "Example input"}, {"invalid_output": "Example output"}), ] - with pytest.raises(ValueError, match="Example output field 'invalid_output' not found in output_variables"): PromptRunner(template_class=InvalidOutputPromptSignature, prompt_strategy=DefaultPromptStrategy) @@ -139,11 +122,9 @@ class InvalidOutputFormatPromptSignature(PromptSignature): input = InputField(name="input", desc="Input field") output1 = OutputField(name="output1", desc="Output field 1") output2 = OutputField(name="output2", desc="Output field 2") - __examples__ = [ ({"input": "Example input"}, "Example output"), ] - with pytest.raises(ValueError, match="Example output must be a dictionary when there are multiple output fields"): PromptRunner(template_class=InvalidOutputFormatPromptSignature, prompt_strategy=DefaultPromptStrategy) @@ -152,20 +133,16 @@ class MultipleOutputPromptSignature(PromptSignature): input = InputField(name="input", desc="Input field") output1 = OutputField(name="output1", desc="Output field 1") output2 = OutputField(name="output2", desc="Output field 2") - __examples__ = [ ({"input": "Example input"}, {"output1": "Example output 1", "output2": "Example output 2"}), ] - prompt_runner = PromptRunner(template_class=MultipleOutputPromptSignature, prompt_strategy=DefaultPromptStrategy) - formatted_prompt = prompt_runner.template._format_openai_prompt( trained_state=None, use_training=True, examples=MultipleOutputPromptSignature.__examples__, input="Test input" ) - assert "✅input: Example input" in formatted_prompt assert "🔑output1: Example output 1" in formatted_prompt assert "🔑output2: Example output 2" in formatted_prompt @@ -175,20 +152,16 @@ class MultipleOutputPromptSignature(PromptSignature): input = InputField(name="input", desc="Input field") output1 = OutputField(name="output1", desc="Output field 1") output2 = OutputField(name="output2", desc="Output field 2") - __examples__ = [ ({"input": "Example input"}, {"output1": "Example output 1", "output2": "Example output 2"}), ] - prompt_runner = PromptRunner(template_class=MultipleOutputPromptSignature, prompt_strategy=DefaultPromptStrategy) - formatted_prompt = prompt_runner.template._format_anthropic_prompt( trained_state=None, use_training=True, examples=MultipleOutputPromptSignature.__examples__, input="Test input" ) - assert "Example input" in formatted_prompt assert "Example output 1" in formatted_prompt assert "Example output 2" in formatted_prompt \ No newline at end of file