mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-02 11:39:18 +00:00
check memory variables (#411)
can have multiple input keys, if some come from memory
This commit is contained in:
@@ -1,10 +1,31 @@
|
||||
"""Test logic on base chain class."""
|
||||
from typing import Dict, List
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.base import Chain, Memory
|
||||
|
||||
|
||||
class FakeMemory(Memory, BaseModel):
|
||||
"""Fake memory class for testing purposes."""
|
||||
|
||||
@property
|
||||
def memory_variables(self) -> List[str]:
|
||||
"""Return baz variable."""
|
||||
return ["baz"]
|
||||
|
||||
def load_memory_variables(self, inputs: Dict[str, Any]) -> Dict[str, str]:
|
||||
"""Return baz variable."""
|
||||
return {"baz": "foo"}
|
||||
|
||||
def save_context(self, inputs: Dict[str, Any], outputs: Dict[str, str]) -> None:
|
||||
"""Pass."""
|
||||
pass
|
||||
|
||||
def clear(self) -> None:
|
||||
"""Pass."""
|
||||
pass
|
||||
|
||||
|
||||
class FakeChain(Chain, BaseModel):
|
||||
@@ -106,3 +127,9 @@ def test_multiple_output_keys_error() -> None:
|
||||
chain = FakeChain(the_output_keys=["foo", "bar"])
|
||||
with pytest.raises(ValueError):
|
||||
chain.run("bar")
|
||||
|
||||
|
||||
def test_run_arg_with_memory() -> None:
|
||||
"""Test run method works when arg is passed."""
|
||||
chain = FakeChain(the_input_keys=["foo", "baz"], memory=FakeMemory())
|
||||
chain.run("bar")
|
||||
|
Reference in New Issue
Block a user