-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
community[patch]: fix qianfan chat stream calling caused exception (#…
…13800) - **Description:** `QianfanChatEndpoint` extends `BaseChatModel` as a super class, which has a default stream implement might concat the MessageChunk with `__add__`. When call stream(), a ValueError for duplicated key will be raise. - **Issues:** * #13546 * #13548 * merge two single test file related to qianfan. - **Dependencies:** no - **Tag maintainer:** --------- Co-authored-by: root <[email protected]> Co-authored-by: Harrison Chase <[email protected]>
- Loading branch information
1 parent
656e87b
commit 70b6315
Showing
4 changed files
with
157 additions
and
76 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
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,53 +0,0 @@ | ||
from typing import cast | ||
|
||
from langchain_core.pydantic_v1 import SecretStr | ||
from pytest import CaptureFixture, MonkeyPatch | ||
|
||
from langchain_community.chat_models.baidu_qianfan_endpoint import ( | ||
QianfanChatEndpoint, | ||
) | ||
|
||
|
||
def test_qianfan_key_masked_when_passed_from_env( | ||
monkeypatch: MonkeyPatch, capsys: CaptureFixture | ||
) -> None: | ||
"""Test initialization with an API key provided via an env variable""" | ||
monkeypatch.setenv("QIANFAN_AK", "test-api-key") | ||
monkeypatch.setenv("QIANFAN_SK", "test-secret-key") | ||
|
||
chat = QianfanChatEndpoint() | ||
print(chat.qianfan_ak, end="") | ||
captured = capsys.readouterr() | ||
assert captured.out == "**********" | ||
|
||
print(chat.qianfan_sk, end="") | ||
captured = capsys.readouterr() | ||
assert captured.out == "**********" | ||
|
||
|
||
def test_qianfan_key_masked_when_passed_via_constructor( | ||
capsys: CaptureFixture, | ||
) -> None: | ||
"""Test initialization with an API key provided via the initializer""" | ||
chat = QianfanChatEndpoint( | ||
qianfan_ak="test-api-key", | ||
qianfan_sk="test-secret-key", | ||
) | ||
print(chat.qianfan_ak, end="") | ||
captured = capsys.readouterr() | ||
assert captured.out == "**********" | ||
|
||
print(chat.qianfan_sk, end="") | ||
captured = capsys.readouterr() | ||
|
||
assert captured.out == "**********" | ||
|
||
|
||
def test_uses_actual_secret_value_from_secret_str() -> None: | ||
"""Test that actual secret is retrieved using `.get_secret_value()`.""" | ||
chat = QianfanChatEndpoint( | ||
qianfan_ak="test-api-key", | ||
qianfan_sk="test-secret-key", | ||
) | ||
assert cast(SecretStr, chat.qianfan_ak).get_secret_value() == "test-api-key" | ||
assert cast(SecretStr, chat.qianfan_sk).get_secret_value() == "test-secret-key" | ||
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