Skip to content

Instantly share code, notes, and snippets.

@thoraxe
Created December 5, 2023 21:53
Show Gist options
  • Save thoraxe/4bd9a6815934f5fad1a9b7b7c3729010 to your computer and use it in GitHub Desktop.
Save thoraxe/4bd9a6815934f5fad1a9b7b7c3729010 to your computer and use it in GitHub Desktop.
========================================================================================= FAILURES =========================================================================================
__________________________________________________________________________________ test_yes_no_classifier __________________________________________________________________________________
yes_no_classifier = <src.query_helpers.yes_no_classifier.YesNoClassifier object at 0x7faa85532d90>, monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7faa860917d0>
def test_yes_no_classifier(yes_no_classifier, monkeypatch):
monkeypatch.setattr(
langchain.chains, "LLMChain", MockLLMChain(desired_response="9")
)
import utils.model_context
class MockChainInterface:
"""
Unfortunately, LangChainInterface is a callable class, which makes
testing extra ugly
"""
def __init__(self, *args, **kwargs):
pass
def __call__(self, *args, **kwargs):
return "test response"
monkeypatch.setattr(utils.model_context, "LangChainInterface", MockChainInterface)
> response = yes_no_classifier.classify(
conversation="1234", statement="The sky is blue."
)
tests/unit/query_helpers/test_yes_no_classifier.py:56:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/query_helpers/yes_no_classifier.py:55: in classify
llm_chain = LLMChain(llm=bare_llm, prompt=prompt_instructions, verbose=verbose)
../../../../.pyenv/versions/fastapi-ols-311/lib/python3.11/site-packages/langchain_core/load/serializable.py:97: in __init__
super().__init__(**kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
__pydantic_self__ = LLMChain()
data = {'llm': <test_yes_no_classifier.test_yes_no_classifier.<locals>.MockChainInterface object at 0x7faa85e9d610>, 'prompt'...se.\nResponse: 0\n\nStatement: Apples are red.\nResponse: 9\n\nStatement: {statement}\nResponse:\n"), 'verbose': False}
values = {'callback_manager': None, 'callbacks': None, 'llm_kwargs': {}, 'memory': None, ...}, fields_set = {'llm', 'prompt', 'verbose'}
validation_error = ValidationError(model='LLMChain', errors=[{'loc': ('llm',), 'msg': 'instance of Runnable expected', 'type': 'type_erro...'instance of Runnable expected', 'type': 'type_error.arbitrary_type', 'ctx': {'expected_arbitrary_type': 'Runnable'}}])
def __init__(__pydantic_self__, **data: Any) -> None:
"""
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
"""
# Uses something other than `self` the first arg to allow "self" as a settable attribute
values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
if validation_error:
> raise validation_error
E pydantic.v1.error_wrappers.ValidationError: 2 validation errors for LLMChain
E llm
E instance of Runnable expected (type=type_error.arbitrary_type; expected_arbitrary_type=Runnable)
E llm
E instance of Runnable expected (type=type_error.arbitrary_type; expected_arbitrary_type=Runnable)
../../../../.pyenv/versions/fastapi-ols-311/lib/python3.11/site-packages/pydantic/v1/main.py:341: ValidationError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment