-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
48 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ __pycache__/ | |
htmlcov/ | ||
.coverage | ||
*.swp | ||
.aider* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
import pytest | ||
from langdspy import PromptRunner, PromptSignature, InputField, OutputField, DefaultPromptStrategy | ||
from langchain_contrib.llms.testing import FakeLLM | ||
|
||
class TestPromptSignature(PromptSignature): | ||
input = InputField(name="input", desc="Input field") | ||
output = OutputField(name="output", desc="Output field") | ||
|
||
def test_fake_anthropic_llm(): | ||
prompt_runner = PromptRunner(template_class=TestPromptSignature, prompt_strategy=DefaultPromptStrategy) | ||
|
||
# Test with default response | ||
llm = FakeLLM() | ||
result = prompt_runner.invoke({"input": "test input"}, config={"llm": llm, "llm_type": "fake_anthropic"}) | ||
from langdspy import PromptRunner, PromptSignature, InputField, OutputField, DefaultPromptStrategy, Model | ||
from langchain_community.llms import FakeListLLM | ||
# from langchain_contrib.llms.testing import FakeLLM | ||
|
||
def create_test_model(): | ||
class TestPromptSignature(PromptSignature): | ||
input = InputField(name="input", desc="Input field") | ||
output = OutputField(name="output", desc="Output field") | ||
|
||
|
||
class TestModel(Model): | ||
p1 = PromptRunner(template_class=TestPromptSignature, prompt_strategy=DefaultPromptStrategy) | ||
|
||
def invoke(self, input: str, config: dict) -> str: | ||
result = self.p1.invoke({"input": input}, config=config) | ||
return result | ||
|
||
return TestModel() | ||
|
||
@pytest.fixture | ||
def test_model(): | ||
return create_test_model() | ||
|
||
|
||
def test_fake_anthropic_llm(test_model): | ||
llm = FakeListLLM(verbose=True, responses=["<output>foo</output>", "<output>bar</output>", "<output>baz</output>"]) | ||
result = test_model.invoke({"input": "test input"}, config={"llm": llm, "llm_type": "fake_anthropic"}) | ||
assert result.output == "foo" | ||
|
||
# Test with custom mapped response | ||
llm = FakeLLM(mapped_responses={"<input>test input</input>": "<output>Custom response</output>"}) | ||
result = prompt_runner.invoke({"input": "test input"}, config={"llm": llm, "llm_type": "fake_anthropic"}) | ||
assert result.output == "Custom response" | ||
|
||
# Test with sequenced responses | ||
llm = FakeLLM(sequenced_responses=["<output>One</output>", "<output>Two</output>", "<output>Three</output>"]) | ||
|
||
result1 = prompt_runner.invoke({"input": "test input"}, config={"llm": llm, "llm_type": "fake_anthropic"}) | ||
assert result1.output == "One" | ||
|
||
result2 = prompt_runner.invoke({"input": "test input"}, config={"llm": llm, "llm_type": "fake_anthropic"}) | ||
assert result2.output == "Two" | ||
|
||
result3 = prompt_runner.invoke({"input": "test input"}, config={"llm": llm, "llm_type": "fake_anthropic"}) | ||
assert result3.output == "Three" | ||
|
||
result4 = prompt_runner.invoke({"input": "test input"}, config={"llm": llm, "llm_type": "fake_anthropic"}) | ||
assert result4.output == "foo" # Default response after exhausting sequenced responses | ||
result = test_model.invoke({"input": "test input"}, config={"llm": llm, "llm_type": "fake_anthropic"}) | ||
assert result.output == "bar" | ||
|
||
result = test_model.invoke({"input": "test input"}, config={"llm": llm, "llm_type": "fake_anthropic"}) | ||
assert result.output == "baz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters