mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-26 08:33:49 +00:00
community[patch]: Standardize qianfan model init args name (#22322)
- **Description:** - Standardize qianfan chat model intialization arguments name - qianfan_ak (qianfan api key) -> api_key - qianfan_sk (qianfan secret key) -> secret_key - Delete unuse variable - **Issue:** #20085
This commit is contained in:
parent
c64b0a3095
commit
596c062cba
@ -133,11 +133,12 @@ class QianfanChatEndpoint(BaseChatModel):
|
|||||||
model_kwargs: Dict[str, Any] = Field(default_factory=dict)
|
model_kwargs: Dict[str, Any] = Field(default_factory=dict)
|
||||||
"""extra params for model invoke using with `do`."""
|
"""extra params for model invoke using with `do`."""
|
||||||
|
|
||||||
client: Any
|
client: Any #: :meta private:
|
||||||
|
|
||||||
qianfan_ak: Optional[SecretStr] = None
|
|
||||||
qianfan_sk: Optional[SecretStr] = None
|
|
||||||
|
|
||||||
|
qianfan_ak: Optional[SecretStr] = Field(default=None, alias="api_key")
|
||||||
|
"""Qianfan API KEY"""
|
||||||
|
qianfan_sk: Optional[SecretStr] = Field(default=None, alias="secret_key")
|
||||||
|
"""Qianfan SECRET KEY"""
|
||||||
streaming: Optional[bool] = False
|
streaming: Optional[bool] = False
|
||||||
"""Whether to stream the results or not."""
|
"""Whether to stream the results or not."""
|
||||||
|
|
||||||
@ -145,7 +146,9 @@ class QianfanChatEndpoint(BaseChatModel):
|
|||||||
"""request timeout for chat http requests"""
|
"""request timeout for chat http requests"""
|
||||||
|
|
||||||
top_p: Optional[float] = 0.8
|
top_p: Optional[float] = 0.8
|
||||||
|
"""What probability mass to use."""
|
||||||
temperature: Optional[float] = 0.95
|
temperature: Optional[float] = 0.95
|
||||||
|
"""What sampling temperature to use."""
|
||||||
penalty_score: Optional[float] = 1
|
penalty_score: Optional[float] = 1
|
||||||
"""Model params, only supported in ERNIE-Bot and ERNIE-Bot-turbo.
|
"""Model params, only supported in ERNIE-Bot and ERNIE-Bot-turbo.
|
||||||
In the case of other model, passing these params will not affect the result.
|
In the case of other model, passing these params will not affect the result.
|
||||||
@ -292,7 +295,6 @@ class QianfanChatEndpoint(BaseChatModel):
|
|||||||
"""
|
"""
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
completion = ""
|
completion = ""
|
||||||
token_usage = {}
|
|
||||||
chat_generation_info: Dict = {}
|
chat_generation_info: Dict = {}
|
||||||
for chunk in self._stream(messages, stop, run_manager, **kwargs):
|
for chunk in self._stream(messages, stop, run_manager, **kwargs):
|
||||||
chat_generation_info = (
|
chat_generation_info = (
|
||||||
@ -337,7 +339,6 @@ class QianfanChatEndpoint(BaseChatModel):
|
|||||||
) -> ChatResult:
|
) -> ChatResult:
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
completion = ""
|
completion = ""
|
||||||
token_usage = {}
|
|
||||||
chat_generation_info: Dict = {}
|
chat_generation_info: Dict = {}
|
||||||
async for chunk in self._astream(messages, stop, run_manager, **kwargs):
|
async for chunk in self._astream(messages, stop, run_manager, **kwargs):
|
||||||
chat_generation_info = (
|
chat_generation_info = (
|
||||||
|
@ -362,3 +362,19 @@ def test_uses_actual_secret_value_from_secret_str() -> None:
|
|||||||
)
|
)
|
||||||
assert cast(SecretStr, chat.qianfan_ak).get_secret_value() == "test-api-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"
|
assert cast(SecretStr, chat.qianfan_sk).get_secret_value() == "test-secret-key"
|
||||||
|
|
||||||
|
|
||||||
|
def test_init_api_key_param() -> None:
|
||||||
|
"""Test the standardized parameters -- api_key and secret_key"""
|
||||||
|
for chat in [
|
||||||
|
QianfanChatEndpoint( # type: ignore[call-arg]
|
||||||
|
api_key="test-api-key", # type: ignore[arg-type]
|
||||||
|
secret_key="test-secret-key", # type: ignore[arg-type]
|
||||||
|
),
|
||||||
|
QianfanChatEndpoint( # type: ignore[call-arg]
|
||||||
|
qianfan_ak="test-api-key", # type: ignore[arg-type]
|
||||||
|
qianfan_sk="test-secret-key", # type: ignore[arg-type]
|
||||||
|
),
|
||||||
|
]:
|
||||||
|
assert cast(SecretStr, chat.qianfan_ak).get_secret_value() == "test-api-key"
|
||||||
|
assert cast(SecretStr, chat.qianfan_sk).get_secret_value() == "test-secret-key"
|
||||||
|
Loading…
Reference in New Issue
Block a user