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

Update Anthropic SDK to 0.5.X to support Claude V2 #1932

Merged
merged 4 commits into from Jul 11, 2023
Merged

Update Anthropic SDK to 0.5.X to support Claude V2 #1932

merged 4 commits into from Jul 11, 2023

Conversation

cwoolum
Copy link
Contributor

@cwoolum cwoolum commented Jul 11, 2023

Anthropic has released Claude V2 which makes use of an updated API. The TypeScript SDK 0.5.X has been rewritten to support the new API schema which also applies to Claude V1.

It should be noted that the TypeScript SDK no longer supports AbortController inherently and so it can only be used for streaming responses to short circuit what is returned by the LangchainJS client.

Fixes # (issue)

@vercel
Copy link

vercel bot commented Jul 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Jul 11, 2023 10:11pm

@dosubot dosubot bot added the auto:improvement Medium size change to existing code to handle new use-cases label Jul 11, 2023
} catch (e: any) {
// Anthropic doesn't actually throw JavaScript error objects at the moment.
// We convert the error so the async caller can recognize it correctly.
if (e?.name === "AbortError") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do they still not throw JS errors?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do; AbortError's in JavaScript weirdly don't have their own class:

Note: When abort() is called, the fetch() promise rejects with an Error of type DOMException, with name AbortError.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh wow that explains a lot. Thanks.

@jacoblee93
Copy link
Collaborator

Thanks for this! It seems like this doesn't pass our integration test:

yarn test:single langchain/src/chat_models/tests/chatanthropic.int.test.ts

Fails the batch request abort test as expected (unfortunately) but also the basic streaming one.

CC @dqbd but I can just have a look as well.

@jacoblee93
Copy link
Collaborator

Fixed things up and added back in abort for both (taking some ideas from #1912!)

Unfortunately, it seems they're doing some things that break edge environments and it's failing our build tests. Will contact them and try to get them to fix it.


if (options.signal?.aborted) {
stream.controller.abort();
throw new Error("AbortError: User aborted the request.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, you might want this to be more like:

const err = new Error("User aborted the request.")
err.name = "AbortError";
throw err;

which I believe to be closer to what JS runtimes do.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets caught by our caller class which would catch this - we could/should change it in the future but it's out of scope for this one.

@jacoblee93
Copy link
Collaborator

Ok, so it's actually intentional and the newest version of next actually supports it via a special case:

vercel/next.js#52009

Bumped the version and it builds locally so it should pass our CI.

@jacoblee93
Copy link
Collaborator

Thanks again @cwoolum! Will be in tonights release 🙂

@jacoblee93 jacoblee93 merged commit 8da80b1 into langchain-ai:main Jul 11, 2023
10 checks passed
@cwoolum
Copy link
Contributor Author

cwoolum commented Jul 11, 2023

Awesome, thanks! Forgot to include my twitter handle if it still matters. @chriswoolum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants