forked from langchain-ai/langchain
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core[patch]: fix ChatGeneration.text with content blocks (langchain-a…
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
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
32 changes: 32 additions & 0 deletions
32
libs/core/tests/unit_tests/outputs/test_chat_generation.py
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,32 @@ | ||
from typing import Union | ||
|
||
import pytest | ||
|
||
from langchain_core.messages import AIMessage | ||
from langchain_core.outputs import ChatGeneration | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"content", | ||
[ | ||
"foo", | ||
["foo"], | ||
[{"text": "foo", "type": "text"}], | ||
[ | ||
{"tool_use": {}, "type": "tool_use"}, | ||
{"text": "foo", "type": "text"}, | ||
"bar", | ||
], | ||
], | ||
) | ||
def test_msg_with_text(content: Union[str, list]) -> None: | ||
expected = "foo" | ||
actual = ChatGeneration(message=AIMessage(content=content)).text | ||
assert actual == expected | ||
|
||
|
||
@pytest.mark.parametrize("content", [[], [{"tool_use": {}, "type": "tool_use"}]]) | ||
def test_msg_no_text(content: Union[str, list]) -> None: | ||
expected = "" | ||
actual = ChatGeneration(message=AIMessage(content=content)).text | ||
assert actual == expected |