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 aws bedrockruntime claude3 #1328

Merged
merged 10 commits into from
Apr 19, 2024

Conversation

Laisky
Copy link
Contributor

@Laisky Laisky commented Apr 18, 2024

closes #622, closes #749, closes #1300

变更

支持了 aws bedrockruntime 的 claude API

支持的模型有:

  • "claude-instant-1.2"
  • "claude-2.0"
  • "claude-2.1"
  • "claude-3-sonnet-20240229"
  • "claude-3-opus-20240229"
  • "claude-3-haiku-20240307"

补充说明

  1. 因为使用了 aws-go-sdk-v2,所以 Go 需要升级到 1.20
  2. gorm 有 bug 导致 migrate 失败,升级了 gorm 依赖
  3. 前端仅修改了 default theme

自测

我已确认该 PR 已自测通过,相关截图如下:

CleanShot 2024-04-18 at 11 22 07@2x

CleanShot 2024-04-18 at 11 22 27@2x

@Laisky Laisky force-pushed the patch/aws-claude branch from 5b960fc to ed716c8 Compare April 18, 2024 03:57
…age metrics

Based on the file summaries provided, here are the important bullet points for the commit message:

- Add functionality to handle stream completion events from AWS in the relay/adaptor/aws/main.go file
- Marshall AWS response to OpenAI format and calculate usage metrics in the same file
- Implement a custom render function for streaming events in the same file
- Improve error handling for JSON unmarshalling and marshalling errors in the same file
@Real00
Copy link

Real00 commented Apr 18, 2024

本地尝试合并到 v0.6.5 发现以下问题:

  1. 测试渠道的时候,界面无反应,服务报错(其他渠道正常)
    image
  2. 非 steam 正常,steam 开启,返回结果不符合预期(实际为文本,也没有带 Content-Type )
    image
    正常应该是这样的
    image

@lp380490944
Copy link

试了一下,应该是有问题的,在 gpt-next-web 这一块不行

@songquanpeng
Copy link
Owner

本周末处理,感谢 pr

- Implemented streaming response handling for AWS handler
- Set response content type to text/event-stream
- Added error handling for failed marshaling/unmarshaling
- Updated return values to include `relaymodel.ErrorWithStatusCode` and `relaymodel.Usage`
- Improved error handling and response formatting for AWS adaptor
@Laisky
Copy link
Contributor Author

Laisky commented Apr 19, 2024

试了一下,应该是有问题的,在 gpt-next-web 这一块不行

看了下,因为 gpt-next-web 是根据 response header 来判断解析逻辑的,所以给 stream 加了一行 header 就好了。

CleanShot 2024-04-19 at 09 54 37@2x

CleanShot 2024-04-19 at 09 55 30@2x

CleanShot 2024-04-19 at 09 56 40@2x

CleanShot 2024-04-19 at 09 56 07@2x

Laisky and others added 6 commits April 19, 2024 02:08
* Refactor AWS adapter to improve model management
  - Replace hardcoded model list in `adapter.go` with a function to get models from `awsModelIDMap`
  - Update `GetModelList` function to return model list directly
  - Add `GetChannelName` function to get channel name from `Adaptor` object
* Improve error handling and code organization in main.go
  - Replace switch statement with a map to map AWS model IDs to OpenAI model IDs
  - Return an error if the model is not found in the map
  - Use a single return statement instead of wrapping multiple return statements in the `awsModelID` function
  - Add a new error message for when the model is not found in the map in the `Handler` function
@songquanpeng songquanpeng merged commit fc9a784 into songquanpeng:main Apr 19, 2024
billing.ReturnPreConsumedQuota(ctx, preConsumedQuota, meta.TokenId)
return RelayErrorHandler(resp)
if resp != nil {
errorHappened := (resp.StatusCode != http.StatusOK) || (meta.IsStream && resp.Header.Get("Content-Type") == "application/json")
Copy link
Contributor

Choose a reason for hiding this comment

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

#1345, When the type is a Gemini streaming response, the content-type remains application/json.

@dirname dirname mentioned this pull request Apr 26, 2024
5 tasks
@Laisky Laisky deleted the patch/aws-claude branch July 17, 2024 02:18
SheldonLiu0412 pushed a commit to SheldonLiu0412/one-api that referenced this pull request Jan 23, 2025
* feat: support aws bedrockruntime claude3

closes songquanpeng#622, closes songquanpeng#749, closes songquanpeng#1300

* fix: convert to aws claude model id

* fix: Update AWS adapter to handle stream completions and calculate usage metrics

Based on the file summaries provided, here are the important bullet points for the commit message:

- Add functionality to handle stream completion events from AWS in the relay/adaptor/aws/main.go file
- Marshall AWS response to OpenAI format and calculate usage metrics in the same file
- Implement a custom render function for streaming events in the same file
- Improve error handling for JSON unmarshalling and marshalling errors in the same file

* fix: Implement AWS handler with usage tracking and error handling

- Implemented streaming response handling for AWS handler
- Set response content type to text/event-stream
- Added error handling for failed marshaling/unmarshaling
- Updated return values to include `relaymodel.ErrorWithStatusCode` and `relaymodel.Usage`
- Improved error handling and response formatting for AWS adaptor

* fix: Refactor AWS Adapter for Improved Model Mapping and Error Handling

* Refactor AWS adapter to improve model management
  - Replace hardcoded model list in `adapter.go` with a function to get models from `awsModelIDMap`
  - Update `GetModelList` function to return model list directly
  - Add `GetChannelName` function to get channel name from `Adaptor` object
* Improve error handling and code organization in main.go
  - Replace switch statement with a map to map AWS model IDs to OpenAI model IDs
  - Return an error if the model is not found in the map
  - Use a single return statement instead of wrapping multiple return statements in the `awsModelID` function
  - Add a new error message for when the model is not found in the map in the `Handler` function

* fix: bug fix

* chore: change variable name & package

* chore: change variable name

* perf: update config related code

---------

Co-authored-by: JustSong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants