langchain
langchain copied to clipboard
Incompatibility with latest Anthropic Client
System Info
Massive client changes as of this pr: https://github.com/anthropics/anthropic-sdk-python/commit/8d1d6af6527a3ef80b74dc3a466166ab7df057df
Installing the latest anthropic client will cause langchain Anthropic LLM utiltiies to fail. Looks like api_url no longer exists (they've moved to base_url).
???
E pydantic.error_wrappers.ValidationError: 1 validation error for ChatAnthropic
E __root__
E __init__() got an unexpected keyword argument 'api_url' (type=type_error)
Who can help?
@hwchase17
Information
- [ ] The official example notebooks/scripts
- [ ] My own modified scripts
Related Components
- [x] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async
Reproduction
- Install latest version of anthropic.
- Attempt to run Anthropic LLM and it will produce a runtime failure about api_url which no longer exists in the Anthropic client initializer.
Expected behavior
Should work with latest release of Anthropic client.
Answer generated by a 🤖
Answer
The error message indicates that the api_url
argument is no longer accepted by the anthropic.Client
initializer. This is due to the recent changes in the Anthropic client where api_url
has been replaced with base_url
.
To fix this issue, you need to replace api_url
with base_url
in the Anthropic
class in your LangChain code. Here's how you can do it:
Replace this code:
values["client"] = anthropic.Client(
api_url=anthropic_api_url,
api_key=anthropic_api_key,
default_request_timeout=values["default_request_timeout"],
)
With this:
values["client"] = anthropic.Client(
base_url=anthropic_api_url,
api_key=anthropic_api_key,
default_request_timeout=values["default_request_timeout"],
)
This change should resolve the issue and make LangChain compatible with the latest version of the Anthropic client.
Sources
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
For those just needing a quick work-around. pip install anthropic==0.2.10
get's you back to the latest version before this change.
@jmkuebler Do you happen to know if this was addressed in another issue/commit to the langchain
library?
@jmkuebler Do you happen to know if this was addressed in another issue/commit to the
langchain
library?
@adityamookerjee No I am not aware of another issue that could be linked.
Hi, @rasharab! I'm Dosu, and I'm helping the LangChain team manage our backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, the latest version of the Anthropic client is incompatible with the langchain Anthropic LLM utilities due to a change in the client's API. The api_url
parameter has been removed and replaced with base_url
. I provided a solution in the comments, suggesting to replace api_url
with base_url
in the Anthropic
class in the LangChain code. Another user, jmkuebler, suggested a quick workaround by installing the previous version of the Anthropic client (0.2.10). There is a question from adityamookerjee asking if this issue was addressed in another issue/commit to the langchain
library, to which jmkuebler replied that they are not aware of any other related issue.
Now, we would like to know if this issue is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.
Thank you for your understanding and cooperation. Let us know if you have any further questions or concerns!
Best regards, Dosu