Commit Graph

63 Commits

Author SHA1 Message Date
Laisky.Cai
c524e60d9f Merge remote-tracking branch 'origin/upstream/main' 2024-05-29 06:12:37 +00:00
JustSong
ceea4c6d4a feat: support user content download proxy & relay proxy now 2024-05-29 01:14:00 +08:00
Mo
332c8db0b3
fix: add prefixes to image models to solve the problem of duplicate models (#1469)
* Add prefixes to image models to solve the problem of duplicate models

* Fix the issue that response_format is not set, causing the b64_json parameter to be ignored.
2024-05-28 01:32:57 +08:00
Laisky.Cai
7f0238e64c Merge remote-tracking branch 'origin/upstream/main' 2024-05-04 00:54:10 +00:00
JustSong
1f76c80553 fix: fix aws claude panic (#1384) 2024-04-29 22:49:06 +08:00
Laisky.Cai
ca23dd9a97 Merge commit '1c2654320e5b6268b13b6efca40ce37a523d032b' 2024-04-28 01:53:31 +00:00
plusye
1c2654320e
fix: fix getPreConsumedQuota (#1312) 2024-04-27 16:07:06 +08:00
JustSong
007906216d feat: support DeepL's model (close #1126) 2024-04-27 13:37:22 +08:00
JustSong
9026ec7510 feat: support cloudflare now 2024-04-26 23:05:48 +08:00
Laisky.Cai
425059f5c6 feat: support openai images edits api 2024-04-25 03:02:20 +00:00
Laisky.Cai
84a6817314 feat: able to fetch every request's cost 2024-04-23 00:58:25 +00:00
Laisky.Cai
7047d9605e Merge commit '3d149fedf45472eff92910324974c762fc37dad6' 2024-04-21 15:05:13 +00:00
JustSong
3d149fedf4 chore: do not hardcode context key 2024-04-21 19:43:23 +08:00
Laisky.Cai
c735b9b4d3 Merge commit '2369025842b828ac38f4427fd1ebab8d03b1fe7f' 2024-04-20 01:07:29 +00:00
JustSong
2369025842 fix: use prefix to match more json response 2024-04-20 01:15:33 +08:00
Laisky.Cai
fc9a784950
feat: support aws bedrockruntime claude3 (#1328)
* feat: support aws bedrockruntime claude3

closes #622, closes #749, closes #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 <songquanpeng@foxmail.com>
2024-04-20 00:40:47 +08:00
Laisky.Cai
4e1bfe4879 feat: support aws bedrockruntime claude3
closes #622, closes #749, closes #1300
2024-04-18 02:52:26 +00:00
Laisky.Cai
50bab08496 Refactor codebase, introduce relaymode package, update constants and improve consistency
- Refactor constant definitions and organization
- Clean up package level variables and functions
- Introduce new `relaymode` and `apitype` packages for constant definitions
- Refactor and simplify code in several packages including `openai`, `relay/channel/baidu`, `relay/util`, `relay/controller`, `relay/channeltype`
- Add helper functions in `relay/channeltype` package to convert channel type constants to corresponding API type constants
- Remove deprecated functions such as `ResponseText2Usage` from `relay/channel/openai/helper.go`
- Modify code in `relay/util/validation.go` and related files to use new `validator.ValidateTextRequest` function
- Rename `util` package to `relaymode` and update related imports in several packages
2024-04-06 05:18:04 +00:00
JustSong
0b8ccb94eb chore: reorganize common package 2024-04-06 02:03:59 +08:00
JustSong
f586ae0ad8 chore: remove helper & util subpackage for relay 2024-04-06 01:50:12 +08:00
JustSong
24ed170e7b chore: reorganize adaptor related package 2024-04-06 01:36:48 +08:00
JustSong
f70506eac1 chore: reorganize relay related package 2024-04-06 01:31:44 +08:00
JustSong
8f4d78e24d chore: reorganize billing related package 2024-04-06 01:26:48 +08:00
JustSong
cd2707692f chore: reorganize billing related package 2024-04-06 01:09:23 +08:00
JustSong
2ab7d25a80 chore: reorganize helper related package 2024-04-06 01:02:35 +08:00
JustSong
f9d914873f chore: reorganize constant related package 2024-04-06 00:44:33 +08:00
JustSong
880e12c855 feat: support cogview-3 2024-04-06 00:30:08 +08:00
Mo
d4347e7a35
feat: support Ali stable-diffusion-xl and wanx-v1 model (#1240)
* Fix ali ConvertRequest function to use baidu keyword

* Support Ali stable-diffusion-xl and wanx-v1 model

* Support Ali stable-diffusion-xl and wanx-v1 model

* Support Ali stable-diffusion-xl and wanx-v1 model

* chore: update ali constants and model ratio

---------

Co-authored-by: JustSong <songquanpeng@foxmail.com>
Co-authored-by: JustSong <39998050+songquanpeng@users.noreply.github.com>
2024-04-05 18:09:54 +08:00
Laisky.Cai
36353a1d96 Merge commit '5b349efff9906d6db9f31644008959250b2c30f9' 2024-03-27 22:09:47 +00:00
JustSong
56ddbb842a fix: return pre-consumed quota when error happened for audio (close #1217) 2024-03-24 22:20:41 +08:00
Laisky.Cai
d379377eca Merge remote-tracking branch 'origin/upstream/main' 2024-03-18 01:31:21 +00:00
Ian Li
ade19ba4a2
feat: update default API version for Azure OpenAI (#994)
* feat: Update default API version for Azure OpenAI.

* chore: update other theme

---------

Co-authored-by: JustSong <songquanpeng@foxmail.com>
2024-03-17 19:34:21 +08:00
Ian Li
4d86d021c4
feat: support Azure OpenAI TTS. (#1177) 2024-03-17 19:30:50 +08:00
Laisky.Cai
41afad713e Merge remote-tracking branch 'origin/upstream/main' 2024-03-15 09:49:49 +00:00
JustSong
79d0cd378a fix: fix baidu system prompt (close #1079) 2024-03-13 22:56:54 +08:00
JustSong
e99150bdb9 fix: make quota int64 2024-03-13 20:00:51 +08:00
JustSong
a72e5fcc9e fix: when cached quota is too low, force refresh it 2024-03-13 19:38:44 +08:00
Laisky.Cai
d953da1ff2 fix: Upgrade error handling to errors/v2 package and refactor error messages.
- Refactor error handling using `errors/v2` package for improved error management and formatting
- Implement changes in relay/controller/text.go, controller/channel-test.go, controller/relay.go, common/message/email.go, relay/controller/audio.go, controller/channel-billing.go, relay/controller/helper.go, relay/channel/common.go, relay/channel/minimax/main.go, and common/message/main.go
- Add package imports and update package paths for better code organization
- Replace hardcoded strings with error variables for consistency and readability
- Implement secure methods for generating unique Message-ID
- Improve SMTP handling and authentication in email.go
- Update response handling and error messages for better user experience
- Add constant checks and modify functions based on imageRequest parameters in helper.go
- Use `http.NewRequest` instead of `fmt.Fprint` for improved request handling in relay/channel/common.go
- Update error handling and formatting for better consistency across all files
2024-03-12 06:43:54 +00:00
Laisky.Cai
54203e3d30 fix: Update error handling to Laisky/errors/v2 package across project
- Updated error handling across multiple files with `Laisky/errors/v2` package
- Replaced hardcoded error messages with `Laisky/errors` in relay/channel/tencent/adaptor.go
- Added a function to check if a request should be retried in relay/controller/relay.go
- Removed unused imports and variables, and updated comments in various files
- Changed Redis cache handling in model/cache.go
- Refactored error handling in relay/channel/tencent/main.go and relay/channel/baidu/main.go
- Updated import paths and error handling in model/user.go, model/redemption.go, and controller/github.go
- Added import for tiktoken-go package in relay/channel/openai/token.go
- Added GetSign and ParseConfig functions in relay/channel/tencent/main.go
- Replaced specific error imports with a more general one in relay/channel/ali/adaptor.go
- Updated import comments and function calls in relay/channel/ali/adaptor.go
- Added checks and custom error messages in model/token.go
- Removed unused functions and variables in relay/channel/baidu/adaptor.go
- Imported "github.com/Laisky/errors/v2" package in controller/channel-billing.go
- Removed unused import packages in [relay/channel/tencent/adaptor.go](http://relay/channel/tencent/adaptor.go) and relay/channel/palm/adaptor.go
- Updated go.mod and go.sum files with new dependencies and versions
2024-03-12 06:40:23 +00:00
Laisky.Cai
72501cb746 Merge remote-tracking branch 'origin/upstream/main' 2024-03-11 09:32:11 +00:00
JustSong
8388aa537f chore: able to search channel now 2024-03-10 14:59:57 +08:00
Laisky.Cai
758378e45a fix: Improve Image Generation Request Handling and Error Messaging
- Implemented error messages with request details and request parameter validation for image requests
- Added URL logic and Azure channel support for image generation requests
- Integrated quota management and updated quota usage logging for image generation requests
- Mapped original model names to mapped model names and unmarshalled image responses into a struct for further processing
2024-03-08 03:42:58 +00:00
Laisky.Cai
cad6f9d3ba fix: Improve quota consumption and logging in relay controller
- Modify `PostConsumeQuota` function in `common.go` to check if `totalQuota` is less than 0 and add error logging
- Update log content in `RecordConsumeLog` function of `common.go` to include model ratio and group ratio
- Change the method of calculating user used quota and request count in `UpdateUserUsedQuotaAndRequestCount` function of `common.go`
- Implement calculation of `completionRatio` and update `quota` calculation based on `completionRatio` in `postConsumeQuota` function of `helper.go`
- Implement error handling for `model.PostConsumeTokenQuota` and `model.CacheUpdateUserQuota` in `helper.go`
- Update `UserUsedQuota` and `ChannelUsedQuota` with new `quota` value in `helper.go`
2024-03-08 03:22:29 +00:00
Laisky.Cai
b1a7e197b7 fix: Log request URL for non-ok status codes
- Refactor: Log full request URL in case of non-ok response
- Fix: URIScheme invalid model in proton-go
2024-03-05 01:08:44 +00:00
Laisky.Cai
cb6cb66646 Merge remote-tracking branch 'origin/upstream/main' 2024-03-05 01:02:35 +00:00
JustSong
9d8967f7d3 feat: support Mistral's models now (close #1051) 2024-03-03 21:46:45 +08:00
JustSong
de18d6fe16 refactor: refactor image relay (close #1068) 2024-03-03 19:30:11 +08:00
JustSong
614c2e0442 feat: support baichuan's models now (close #1057) 2024-03-02 00:55:48 +08:00
Laisky.Cai
06350ae5a2 fix: Refactor: Remove Quota Consumption Logic When Quota is 0
- Remove quota consumption logic when quota is 0
- Improve logging of quota usage when quota is greater than 0
- Reduce noise in logs when quota is 0
2024-03-01 14:00:50 +00:00
Laisky.Cai
dbe3930a8c fix: Switch to channel-ratio
- Use channel ratios instead of group ratios in all applicable places
- Start using the lowest channel ratio of the specified channel's groups
2024-03-01 13:49:23 +00:00