anthropic[patch]: update base_url of anthropic (#18634)

A small change ~

- [ ] **update base_url**: "package: langchain_anthropic"

---------

Co-authored-by: yangenfeng <yangenfeng@xiaoniangao.com>
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
enfeng 2024-03-21 12:04:55 +08:00 committed by GitHub
parent a9cda536ad
commit b20c2640da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -201,11 +201,16 @@ class ChatAnthropic(BaseChatModel):
values.get("anthropic_api_key") or os.environ.get("ANTHROPIC_API_KEY") or ""
)
values["anthropic_api_key"] = anthropic_api_key
values["_client"] = anthropic.Client(
api_key=anthropic_api_key.get_secret_value()
api_key = anthropic_api_key.get_secret_value()
api_url = (
values.get("anthropic_api_url")
or os.environ.get("ANTHROPIC_API_URL")
or "https://api.anthropic.com"
)
values["anthropic_api_url"] = api_url
values["_client"] = anthropic.Client(api_key=api_key, base_url=api_url)
values["_async_client"] = anthropic.AsyncClient(
api_key=anthropic_api_key.get_secret_value()
api_key=api_key, base_url=api_url
)
return values