-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core[patch]: On Chain Start Fix for
Chain
Class (#26593)
- **Issue:** #26588 --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
- Loading branch information
1 parent
bba7af9
commit 154a5ff
Showing
2 changed files
with
52 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Any, Dict, List, Optional | ||
|
||
import pytest | ||
|
||
from langchain.callbacks import StdOutCallbackHandler | ||
from langchain.chains.base import CallbackManagerForChainRun, Chain | ||
|
||
|
||
class FakeChain(Chain): | ||
"""Fake chain class for testing purposes.""" | ||
|
||
be_correct: bool = True | ||
the_input_keys: List[str] = ["foo"] | ||
the_output_keys: List[str] = ["bar"] | ||
|
||
@property | ||
def input_keys(self) -> List[str]: | ||
"""Input keys.""" | ||
return self.the_input_keys | ||
|
||
@property | ||
def output_keys(self) -> List[str]: | ||
"""Output key of bar.""" | ||
return self.the_output_keys | ||
|
||
def _call( | ||
self, | ||
inputs: Dict[str, str], | ||
run_manager: Optional[CallbackManagerForChainRun] = None, | ||
) -> Dict[str, str]: | ||
return {"bar": "bar"} | ||
|
||
|
||
def test_stdoutcallback(capsys: pytest.CaptureFixture) -> Any: | ||
"""Test the stdout callback handler.""" | ||
chain_test = FakeChain(callbacks=[StdOutCallbackHandler(color="red")]) | ||
chain_test.invoke({"foo": "bar"}) | ||
# Capture the output | ||
captured = capsys.readouterr() | ||
# Assert the output is as expected | ||
assert captured.out == ( | ||
"\n\n\x1b[1m> Entering new FakeChain " | ||
"chain...\x1b[0m\n\n\x1b[1m> Finished chain.\x1b[0m\n" | ||
) |