Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix secrets serialisation for ChatAnthropic #7300

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix secrets serialisation for ChatAnthropic
  • Loading branch information
dqbd committed Jul 6, 2023
commit 1a07c81847e90fcfbef222cf5d81e1159b712f8e
4 changes: 4 additions & 0 deletions langchain/chat_models/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class ChatAnthropic(BaseChatModel, _AnthropicCommon):
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
def _llm_type(self) -> str:
"""Return type of chat model."""
Expand Down
12 changes: 6 additions & 6 deletions langchain/llms/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class _AnthropicCommon(BaseModel):
@root_validator()
def validate_environment(cls, values: Dict) -> Dict:
"""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"
)
# Get custom api url from environment.
anthropic_api_url = get_from_dict_or_env(
values["anthropic_api_url"] = get_from_dict_or_env(
values,
"anthropic_api_url",
"ANTHROPIC_API_URL",
Expand All @@ -72,13 +72,13 @@ def validate_environment(cls, values: Dict) -> Dict:
f"`pip install -U anthropic`"
)
values["client"] = anthropic.Anthropic(
base_url=anthropic_api_url,
api_key=anthropic_api_key,
base_url=values["anthropic_api_url"],
api_key=values["anthropic_api_key"],
timeout=values["default_request_timeout"],
)
values["async_client"] = anthropic.AsyncAnthropic(
base_url=anthropic_api_url,
api_key=anthropic_api_key,
base_url=values["anthropic_api_url"],
api_key=values["anthropic_api_key"],
timeout=values["default_request_timeout"],
)
values["HUMAN_PROMPT"] = anthropic.HUMAN_PROMPT
Expand Down