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

โœจ feat: support anthropic as model provider #1409

Merged
merged 11 commits into from
Mar 5, 2024

Conversation

danielglh
Copy link
Contributor

@danielglh danielglh commented Feb 28, 2024

๐Ÿ’ป ๅ˜ๆ›ด็ฑปๅž‹ | Change Type

  • โœจ feat
  • ๐Ÿ› fix
  • โ™ป๏ธ refactor
  • ๐Ÿ’„ style
  • ๐Ÿ”จ chore
  • โšก๏ธ perf
  • ๐Ÿ“ docs

๐Ÿ”€ ๅ˜ๆ›ด่ฏดๆ˜Ž | Description of Change

Added a new model provider, Anthropic, along with the 3 models it currently provides.

image image image

close #1401

๐Ÿ“ ่กฅๅ……ไฟกๆฏ | Additional Information

Anthropic API Geographic Restrictions

Here is a list of locations that Anthropic API supports: https://docs.anthropic.com/claude/reference/supported-regions.

If a lobe-chat service happens to be deployed to a location that it doesn't support, it will not work and it will return 403 errors. For example, you may notice that it doesn't always work on Vercel.ai because Vercel deploys code to its edge server around the world and usually uses the edge server that is closest to your location to serve your requests, and some of its edge servers may not be allowed to make requests to Anthropic API.

Different API Parameters

As far as I know, Anthropic API doesn't seem to support these parameters: presence_penalty, frequency_penalty. Therefore these settings do not affect Anthropic models.

Copy link

vercel bot commented Feb 28, 2024

@danielglh is attempting to deploy a commit to the LobeHub Team on Vercel.

A member of the Team first needs to authorize it.

@lobehubbot
Copy link
Member

๐Ÿ‘ @danielglh

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
้žๅธธๆ„Ÿ่ฐขๆ‚จๆๅ‡บๆ‹‰ๅ–่ฏทๆฑ‚ๅนถไธบๆˆ‘ไปฌ็š„็คพๅŒบๅšๅ‡บ่ดก็Œฎ๏ผŒ่ฏท็กฎไฟๆ‚จๅทฒ็ป้ตๅพชไบ†ๆˆ‘ไปฌ็š„่ดก็ŒฎๆŒ‡ๅ—๏ผŒๆˆ‘ไปฌไผšๅฐฝๅฟซๅฎกๆŸฅๅฎƒใ€‚
ๅฆ‚ๆžœๆ‚จ้‡ๅˆฐไปปไฝ•้—ฎ้ข˜๏ผŒ่ฏท้šๆ—ถไธŽๆˆ‘ไปฌ่”็ณปใ€‚

Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 86.92308% with 34 lines in your changes are missing coverage. Please review.

Project coverage is 92.37%. Comparing base (aaedfa7) to head (035e6dd).
Report is 2 commits behind head on main.

Files Patch % Lines
src/libs/agent-runtime/anthropic/index.ts 82.35% 21 Missing โš ๏ธ
src/app/api/chat/[provider]/agentRuntime.ts 38.46% 8 Missing โš ๏ธ
src/app/api/errorResponse.ts 33.33% 2 Missing โš ๏ธ
src/services/_auth.ts 50.00% 2 Missing โš ๏ธ
src/services/file.ts 0.00% 1 Missing โš ๏ธ
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1409      +/-   ##
==========================================
- Coverage   92.48%   92.37%   -0.12%     
==========================================
  Files         227      230       +3     
  Lines       12022    12278     +256     
  Branches     1457     1483      +26     
==========================================
+ Hits        11119    11342     +223     
- Misses        903      936      +33     

โ˜” View full report in Codecov by Sentry.
๐Ÿ“ข Have feedback on the report? Share it here.

Copy link
Contributor

@arvinxx arvinxx left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! A really nice work. Most of codes are LGTM. Please rebase the main branch and add a test for this provider~ (you can refer to MoonshotAI 's test)

@danielglh danielglh force-pushed the feat-anthropic-models branch 3 times, most recently from 9c22cfd to 5b108d7 Compare February 29, 2024 08:46
@danielglh
Copy link
Contributor Author

Thanks for your PR! A really nice work. Most of codes are LGTM. Please rebase the main branch and add a test for this provider~ (you can refer to MoonshotAI 's test)

Cool. I've rebased main branch and made necessary changes. Regarding test, Anthropic API is not compatible with OpenAI API so it probably takes more time to work on it. I noticed that other providers that are not compatible with OpenAI API don't have tests either. Not sure where to find a better reference.

@arvinxx
Copy link
Contributor

arvinxx commented Feb 29, 2024

@danielglh I will add the google provider test soon. And you can use the simmliar method to add tests:

@danielglh
Copy link
Contributor Author

@arvinxx sure will take a look

@danielglh danielglh force-pushed the feat-anthropic-models branch from 3f6461b to e75b380 Compare February 29, 2024 14:58
@danielglh
Copy link
Contributor Author

Hmm probably need to take some time to check how the streaming should be implemented. For some reason it's quite unstable.

@arvinxx
Copy link
Contributor

arvinxx commented Feb 29, 2024

@danielglh what's the mean of the streaming is unstable?

@danielglh
Copy link
Contributor Author

@danielglh what's the mean of the streaming is unstable?

@arvinxx for some reason the response stream was cut randomly when it was deployed to Vercel for preview

@danielglh
Copy link
Contributor Author

danielglh commented Mar 1, 2024

@arvinxx I think it might be limitations of the edge servers Vercel uses for preview. The streaming works perfectly fine when I run lobe-chat locally and on a remote dev server I have.

@arvinxx
Copy link
Contributor

arvinxx commented Mar 1, 2024

@danielglh I know there is a timeout of stream on vercel, but I don't know the accurate value.

@@ -21,6 +21,14 @@
"sessionWithName": "ะะฐัั‚ั€ะพะนะบะธ ัะตะฐะฝัะฐ ยท {{name}}"
},
"llm": {
"Anthropic": {
"title": "ะะฝั‚ั€ะพะฟะฝั‹ะน",

Choose a reason for hiding this comment

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

I think it's not worth translating, but leaving the Anthropic. So that it doesn't seem like it's a machine translation

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shigomany I agree but this seems to be a general issue to solve in the i18n project. Other providers' titles were mostly translated already

Copy link
Contributor

Choose a reason for hiding this comment

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

I consider to fix it later

@danielglh danielglh force-pushed the feat-anthropic-models branch 3 times, most recently from 4ad0a01 to 4bce423 Compare March 3, 2024 03:52
@danielglh
Copy link
Contributor Author

Thanks for your PR! A really nice work. Most of codes are LGTM. Please rebase the main branch and add a test for this provider~ (you can refer to MoonshotAI 's test)

@arvinxx tests added for Anthropic, plz check again

@danielglh danielglh force-pushed the feat-anthropic-models branch from 4bce423 to ab8249b Compare March 3, 2024 07:54
@ckt1031
Copy link

ckt1031 commented Mar 4, 2024

Now claude-3.0 is released

@arvinxx
Copy link
Contributor

arvinxx commented Mar 4, 2024

@ckt1031 yes, @danielglh can we support Anthropic's new model in the PR?

@ckt1031
Copy link

ckt1031 commented Mar 4, 2024

@ckt1031 yes, @danielglh can we support Anthropic's new model in the PR?

I believe not only adding the new model, but also support vision feature by Claude 3.0 ๐Ÿ˜….

@arvinxx arvinxx force-pushed the feat-anthropic-models branch from ab8249b to 5af03f6 Compare March 4, 2024 18:23
@arvinxx
Copy link
Contributor

arvinxx commented Mar 5, 2024

@ckt1031 yes, @danielglh can we support Anthropic's new model in the PR?

I believe not only adding the new model, but also support vision feature by Claude 3.0 ๐Ÿ˜….

I have supported the vision

@arvinxx
Copy link
Contributor

arvinxx commented Mar 5, 2024

@danielglh can you fix the test of anthropic test? I think the rest is well done enough to ship.

Copy link

vercel bot commented Mar 5, 2024

The latest updates on your projects. Learn more about Vercel for Git โ†—๏ธŽ

Name Status Preview Comments Updated (UTC)
lobe-chat โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Mar 5, 2024 2:39pm

@danielglh danielglh force-pushed the feat-anthropic-models branch from da692a1 to 206fb76 Compare March 5, 2024 07:59
@danielglh
Copy link
Contributor Author

@danielglh can you fix the test of anthropic test? I think the rest is well done enough to ship.

@arvinxx tests fixed

@danielglh
Copy link
Contributor Author

@arvinxx I'm testing this on Vercel and still experiencing weird streaming problems:

image

Any suggestions? Cannot reproduce the issue in the local dev environment. It runs perfectly fine locally.

@danielglh
Copy link
Contributor Author

danielglh commented Mar 5, 2024

Found it ... not sure if it is a Vercel issue or an Anthropic SDK issue yet.

anthropics/anthropic-sdk-typescript#292

I would suggest that we go ahead and ship this first. Not everyone uses Vercel. We just need to make it clear that there's a known issue with Vercel (maybe include it in the document?).

@arvinxx
Copy link
Contributor

arvinxx commented Mar 5, 2024

@danielglh I agree.

@danielglh
Copy link
Contributor Author

@arvinxx documents updated regarding the known issue with Anthropic SDK on Vercel/Cloudflare edge runtime.

@arvinxx arvinxx merged commit a42cf8c into lobehub:main Mar 5, 2024
2 of 5 checks passed
@lobehubbot
Copy link
Member

โค๏ธ Great PR @danielglh โค๏ธ

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.
้กน็›ฎ็š„ๆˆ้•ฟ็ฆปไธๅผ€็”จๆˆทๅ้ฆˆๅ’Œ่ดก็Œฎ๏ผŒๆ„Ÿ่ฐขๆ‚จ็š„่ดก็Œฎ! ๅฆ‚ๆžœๆ‚จๅฏน LobeHub ๅผ€ๅ‘่€…็คพๅŒบๆ„Ÿๅ…ด่ถฃ๏ผŒ่ฏทๅŠ ๅ…ฅๆˆ‘ไปฌ็š„ discord๏ผŒ็„ถๅŽ็งไฟก @arvinxx ๆˆ– @canisminor1990ใ€‚ไป–ไปฌไผš้‚€่ฏทๆ‚จๅŠ ๅ…ฅๆˆ‘ไปฌ็š„็งๅฏ†ๅผ€ๅ‘่€…้ข‘้“ใ€‚ๆˆ‘ไปฌๅฐ†ไผš่ฎจ่ฎบๅ…ณไบŽ Lobe Chat ็š„ๅผ€ๅ‘๏ผŒๅˆ†ไบซๅ’Œ่ฎจ่ฎบๅ…จ็ƒ่Œƒๅ›ดๅ†…็š„ AI ๆถˆๆฏใ€‚

github-actions bot pushed a commit that referenced this pull request Mar 5, 2024
## [Version 0.132.0](v0.131.0...v0.132.0)
<sup>Released on **2024-03-05**</sup>

#### โœจ Features

- **misc**: Support anthropic as model provider.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Support anthropic as model provider, closes [#1409](#1409) ([a42cf8c](a42cf8c))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Member

๐ŸŽ‰ This PR is included in version 0.132.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

573dave pushed a commit to 573dave/lobe-chat that referenced this pull request Mar 5, 2024
* โœจ feat: support anthropic as model provider

* โœจ feat: support anthropic with vision

* โœ… test: fix some with test

* ๐Ÿ› fix: anthropic error handling

* โœ… chore: fix broken tests

* ๐Ÿ› fix: remove unused imports

* ๐Ÿ“ doc: add note for anthropic with vercel/cloudflare

* ๐Ÿ“ docs: update docs

* ๐Ÿ“ docs: update docs

* ๐Ÿ’„ style: update claude icons

* ๐Ÿ’„ style: update tags

---------

Co-authored-by: arvinxx <[email protected]>
573dave pushed a commit to 573dave/lobe-chat that referenced this pull request Mar 5, 2024
## [Version&nbsp;0.132.0](lobehub/lobe-chat@v0.131.0...v0.132.0)
<sup>Released on **2024-03-05**</sup>

#### โœจ Features

- **misc**: Support anthropic as model provider.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Support anthropic as model provider, closes [lobehub#1409](lobehub#1409) ([a42cf8c](lobehub@a42cf8c))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
github-actions bot pushed a commit to bentwnghk/lobe-chat that referenced this pull request Mar 5, 2024
## [Version&nbsp;1.14.0](v1.13.0...v1.14.0)
<sup>Released on **2024-03-05**</sup>

#### โœจ Features

- **misc**: Support anthropic as model provider.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Support anthropic as model provider, closes [lobehub#1409](https://github.com/bentwnghk/lobe-chat/issues/1409) ([a42cf8c](a42cf8c))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
miroshar-success added a commit to miroshar-success/OpenAI_Integraion_platform that referenced this pull request Apr 5, 2024
## [Version&nbsp;0.132.0](lobehub/lobe-chat@v0.131.0...v0.132.0)
<sup>Released on **2024-03-05**</sup>

#### โœจ Features

- **misc**: Support anthropic as model provider.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Support anthropic as model provider, closes [#1409](lobehub/lobe-chat#1409) ([a42cf8c](lobehub/lobe-chat@a42cf8c))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ๆ€Žไนˆ้…็ฝฎAnthropic็š„Claude็š„APIๅˆฐๅŠฉๆ‰‹ๅ‘ข?
5 participants