mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
Fix secrets serialisation for ChatAnthropic (#7300)
This commit is contained in:
parent
cb9ff6efb8
commit
12d14f8947
@ -34,6 +34,10 @@ class ChatAnthropic(BaseChatModel, _AnthropicCommon):
|
|||||||
model = ChatAnthropic(model="<model_name>", anthropic_api_key="my-api-key")
|
model = ChatAnthropic(model="<model_name>", anthropic_api_key="my-api-key")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def lc_secrets(self) -> Dict[str, str]:
|
||||||
|
return {"anthropic_api_key": "ANTHROPIC_API_KEY"}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _llm_type(self) -> str:
|
def _llm_type(self) -> str:
|
||||||
"""Return type of chat model."""
|
"""Return type of chat model."""
|
||||||
|
@ -50,11 +50,11 @@ class _AnthropicCommon(BaseModel):
|
|||||||
@root_validator()
|
@root_validator()
|
||||||
def validate_environment(cls, values: Dict) -> Dict:
|
def validate_environment(cls, values: Dict) -> Dict:
|
||||||
"""Validate that api key and python package exists in environment."""
|
"""Validate that api key and python package exists in environment."""
|
||||||
anthropic_api_key = get_from_dict_or_env(
|
values["anthropic_api_key"] = get_from_dict_or_env(
|
||||||
values, "anthropic_api_key", "ANTHROPIC_API_KEY"
|
values, "anthropic_api_key", "ANTHROPIC_API_KEY"
|
||||||
)
|
)
|
||||||
# Get custom api url from environment.
|
# Get custom api url from environment.
|
||||||
anthropic_api_url = get_from_dict_or_env(
|
values["anthropic_api_url"] = get_from_dict_or_env(
|
||||||
values,
|
values,
|
||||||
"anthropic_api_url",
|
"anthropic_api_url",
|
||||||
"ANTHROPIC_API_URL",
|
"ANTHROPIC_API_URL",
|
||||||
@ -72,13 +72,13 @@ class _AnthropicCommon(BaseModel):
|
|||||||
f"`pip install -U anthropic`"
|
f"`pip install -U anthropic`"
|
||||||
)
|
)
|
||||||
values["client"] = anthropic.Anthropic(
|
values["client"] = anthropic.Anthropic(
|
||||||
base_url=anthropic_api_url,
|
base_url=values["anthropic_api_url"],
|
||||||
api_key=anthropic_api_key,
|
api_key=values["anthropic_api_key"],
|
||||||
timeout=values["default_request_timeout"],
|
timeout=values["default_request_timeout"],
|
||||||
)
|
)
|
||||||
values["async_client"] = anthropic.AsyncAnthropic(
|
values["async_client"] = anthropic.AsyncAnthropic(
|
||||||
base_url=anthropic_api_url,
|
base_url=values["anthropic_api_url"],
|
||||||
api_key=anthropic_api_key,
|
api_key=values["anthropic_api_key"],
|
||||||
timeout=values["default_request_timeout"],
|
timeout=values["default_request_timeout"],
|
||||||
)
|
)
|
||||||
values["HUMAN_PROMPT"] = anthropic.HUMAN_PROMPT
|
values["HUMAN_PROMPT"] = anthropic.HUMAN_PROMPT
|
||||||
|
Loading…
Reference in New Issue
Block a user