Commit Graph

51 Commits

Author SHA1 Message Date
Laisky.Cai
f322f8029d fix: enhance token status handling in UpdateToken function with additional cases 2024-11-20 03:02:21 +00:00
Laisky.Cai
0d9c79be35 fix: update Go base image version and enhance token status checks in UpdateToken function 2024-11-20 02:52:09 +00:00
Laisky.Cai
0e335db90c feat: add remaining quota and status fields to token update 2024-11-20 02:43:41 +00:00
Laisky.Cai
4fd0b247d2 chore: decrease token quota in ConsumeToken function
This commit modifies the ConsumeToken function in the token.go file to decrease the token quota by the specified amount. It replaces the previous code that directly updated the quota values with a call to the DecreaseTokenQuota function from the model package. This change improves code clarity and maintainability.

Closes #123
2024-06-25 06:15:07 +00:00
Laisky.Cai
671039f050 fix: Update AddUsedQuota data type in consumeTokenRequest struct 2024-06-25 06:08:33 +00:00
Laisky.Cai
078be37e87 chore: Update consumeTokenRequest struct in token.go for better clarity 2024-06-24 08:20:49 +00:00
Laisky.Cai
4eade81869 chore: add endpoint for consuming tokens
This commit adds a new endpoint `/token/consume` to the API router, allowing users to consume tokens from another source. It includes changes to the `token.go` file in the `controller` package.
2024-06-24 07:58:14 +00:00
Laisky.Cai
a8cc96bf4a chore: update token.go to record consumption log 2024-06-24 06:14:58 +00:00
Laisky.Cai
1d82e509aa chore: refactor updateTokenDto struct in token.go for better clarity 2024-06-24 06:06:57 +00:00
Laisky.Cai
0e35db82d5 chore: Update token.go to allow admin to add or subtract used quota 2024-06-24 05:52:23 +00:00
Laisky.Cai
c524e60d9f Merge remote-tracking branch 'origin/upstream/main' 2024-05-29 06:12:37 +00:00
Laisky.Cai
ca23dd9a97 Merge commit '1c2654320e5b6268b13b6efca40ce37a523d032b' 2024-04-28 01:53:31 +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
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
2ab7d25a80 chore: reorganize helper related package 2024-04-06 01:02:35 +08:00
JustSong
348adc2b02 feat: able to set multiple subnets 2024-04-05 17:25:28 +08:00
JustSong
68605800af feat: add subnet validation (#1275) 2024-04-05 10:18:42 +08:00
JustSong
c49778c254 feat: now able to limit ip range for token now (close #1275) 2024-04-05 10:09:16 +08:00
JustSong
ed70881a58 fix: fix token create 2024-04-04 11:18:21 +08:00
JustSong
dc7aaf2de5 feat: able to set model limitation for token (close #178) 2024-04-04 02:08:18 +08:00
Laisky.Cai
36353a1d96 Merge commit '5b349efff9906d6db9f31644008959250b2c30f9' 2024-03-27 22:09:47 +00:00
JustSong
cdfdeea3b4 feat: return token when calling post /api/token (close #1208) 2024-03-24 22:24:41 +08:00
Laisky.Cai
d379377eca Merge remote-tracking branch 'origin/upstream/main' 2024-03-18 01:31:21 +00:00
Benny
9821bc7281
feat: add user list sorting and pagination enhancements (#1178)
* feat: add user list sorting and pagination enhancements

* feat: add user list sorting for THEME=air

* feat: add token list sorting and pagination enhancements

* feat: add token list sorting for THEME=air
2024-03-17 19:25:36 +08:00
Laisky.Cai
41afad713e Merge remote-tracking branch 'origin/upstream/main' 2024-03-15 09:49:49 +00:00
Laisky.Cai
10cbe63c0d Merge remote-tracking branch 'origin/upstream/main' 2024-01-28 13:44:16 +00:00
JustSong
2cd1a78203 chore: update module name 2024-01-28 19:38:58 +08:00
JustSong
2d760d4a01
refactor: refactor relay part (#957)
* refactor: refactor relay part

* refactor: refactor config part
2024-01-21 23:21:42 +08:00
Laisky.Cai
a0dc7e6fd6 refactor: Refactor token handling in the controller
- Remove the unnecessary `AddRemainQuota` field from `updateTokenDto` struct
- Adjust `cleanToken.RemainQuota` by subtracting `tokenPatch.AddUsedQuota`
- Increase `cleanToken.UsedQuota` by adding `tokenPatch.AddUsedQuota`
- Update `model.RecordLog` call to include `tokenPatch.AddReason` and `tokenPatch.AddUsedQuota` values
2023-11-16 05:24:56 +00:00
Laisky.Cai
edacd13025 feat:Exclude fields from database schema and add additional field to struct
- Add `gorm:"-"` tag to exclude certain fields from the database schema
- Add `AddReason` field to the `updateTokenDto` struct
- Record consumption log if `AddUsedQuota` is non-zero
- Record token quota modification log if `AddRemainQuota` is non-zero
- Update and save `cleanToken` with new values
2023-11-16 04:53:08 +00:00
Laisky.Cai
bc8ceca742 feat: api can modify token's used and remains
- Updated base image in Dockerfile from `node:16` to `node:18`
- Added `tokenPatch` struct to handle updates to the `Token` model
- Updated `UpdateToken` function to use `tokenPatch` struct for binding JSON
- Improved error handling and validation for token updates
- Refined checks for token status, expiration, and quota
- Enhanced error handling and response for token updates
- Updated JSON response to include `data` field
2023-09-30 00:53:55 +00:00
JustSong
2a527ee436 fix: fix token name too long 2023-08-12 16:58:29 +08:00
Yolo°
c58f710227
feat: improve frontend (#387)
* fork

* fork

* chore: update style

---------

Co-authored-by: JustSong <songquanpeng@foxmail.com>
2023-08-12 10:49:30 +08:00
JustSong
f0c40a6cd0 fix: fix cannot enable token if set to unlimited time (close #230) 2023-07-02 14:47:06 +08:00
JustSong
2847a08852 feat: the format of key is now constant with that of OpenAI 2023-06-03 10:53:25 +08:00
JustSong
ea8e7c517b fix: fix token quota not updated 2023-05-16 12:09:17 +08:00
JustSong
01abed0a30 refactor: bind quota to account instead of token (close #64, #31) 2023-05-16 11:26:09 +08:00
JustSong
e6af636fa0 fix: the initial quota for new token now calculated correctly (#51) 2023-05-11 21:29:05 +08:00
JustSong
3071300c0c feat: support API /dashboard/billing/credit_grants now (#45) 2023-05-10 09:28:41 +08:00
JustSong
601fa5cea8 refactor: use quota instead of times 2023-04-28 14:57:20 +08:00
JustSong
b9cc5dfa3f feat: able to set initial quota for new user (close #22) 2023-04-26 21:40:56 +08:00
JustSong
9e2f2383b9 feat: now user can top up via redemption code (close #9) 2023-04-26 17:02:26 +08:00
JustSong
03491029f2 feat: limit the ability of common user to set the remaining usage times of token (#9) 2023-04-26 11:10:14 +08:00
JustSong
109736cc05 fix: only reduce remain times when request /v1/chat/completions (close #15)
BREAKING CHANGE: now remain_times is -1 doesn't mean unlimited times anymore!
2023-04-26 10:45:34 +08:00
JustSong
918ba60802 feat: able to set the token's expiration time and number of uses 2023-04-24 20:52:40 +08:00
JustSong
63da6dc6a0 Able to manage token now 2023-04-23 12:43:10 +08:00