Commit Graph

52 Commits

Author SHA1 Message Date
CaIon
6aec088693 feat: add special user usable group setting 2025-10-28 23:25:43 +08:00
Seefs
5010f2d004 format: package name -> github.com/QuantumNous/new-api (#2017) 2025-10-11 15:30:09 +08:00
CaIon
c9e9a24e99 refactor: centralize logging and update resource initialization
This commit refactors the logging mechanism across the application by replacing direct logger calls with a centralized logging approach using the `common` package. Key changes include:

- Replaced instances of `logger.SysLog` and `logger.FatalLog` with `common.SysLog` and `common.FatalLog` for consistent logging practices.
- Updated resource initialization error handling to utilize the new logging structure, enhancing maintainability and readability.
- Minor adjustments to improve code clarity and organization throughout various modules.

This change aims to streamline logging and improve the overall architecture of the codebase.
2025-08-14 21:10:04 +08:00
CaIon
97ea8b6560 refactor: Introduce pre-consume quota and unify relay handlers
This commit introduces a major architectural refactoring to improve quota management, centralize logging, and streamline the relay handling logic.

Key changes:
- **Pre-consume Quota:** Implements a new mechanism to check and reserve user quota *before* making the request to the upstream provider. This ensures more accurate quota deduction and prevents users from exceeding their limits due to concurrent requests.

- **Unified Relay Handlers:** Refactors the relay logic to use generic handlers (e.g., `ChatHandler`, `ImageHandler`) instead of provider-specific implementations. This significantly reduces code duplication and simplifies adding new channels.

- **Centralized Logger:** A new dedicated `logger` package is introduced, and all system logging calls are migrated to use it, moving this responsibility out of the `common` package.

- **Code Reorganization:** DTOs are generalized (e.g., `dalle.go` -> `openai_image.go`) and utility code is moved to more appropriate packages (e.g., `common/http.go` -> `service/http.go`) for better code structure.
2025-08-14 20:05:06 +08:00
CaIon
b3a1948a7b feat: enhance AddAbilities and BatchInsertChannels to support transaction handling 2025-08-08 18:36:09 +08:00
CaIon
f4f73016bf fix: improve error handling and readability in ability.go 2025-08-02 14:06:12 +08:00
CaIon
fad5fc3f7d feat: truncate abilities table before processing channels 2025-08-02 13:39:53 +08:00
CaIon
360012bed2 feat: support claude convert to gemini 2025-07-26 13:31:33 +08:00
CaIon
c773584ecd fix: 修复playground优先级失效 2025-07-17 22:26:38 +08:00
CaIon
beb6ea96d2 feat(ability): enhance FixAbility function 2025-07-08 18:33:32 +08:00
CaIon
f14f4eaf1a feat: refactor environment variable initialization and introduce new constant types for API and context keys 2025-07-03 13:10:25 +08:00
CaIon
a9ec62eea8 🐛 fix(ability, channel): standardize boolean value handling across database queries 2025-06-14 18:15:45 +08:00
CaIon
4371717c78 fix: Resolving conflicts caused by mixing multiple databases 2025-06-14 17:51:05 +08:00
Apple\Apple
f4874c2c1d feat(ui): add incremental-add feedback & translations for model lists (#1218)
Front-end enhancements around “Add custom models”:

• EditChannel.js / EditTagModal.js
  – Skip models that already exist instead of blocking the action.
  – Collect actually inserted items and display:
      • Success toast: “Added N models: model1, model2 …”
      • Info toast when no new model detected.
  – Keeps UX smooth while preserving deduplication logic.

• i18n
  – en.json: added keys
      • "已新增 {{count}} 个模型:{{list}}"
      • "未发现新增模型"
  – Fixed a broken JSON string containing smart quotes to maintain valid syntax.

Result:
Users can bulk-paste model names; duplicates are silently ignored and the UI clearly lists what was incrementally appended. All messages are fully internationalised.

Closes #1218
2025-06-13 13:49:15 +08:00
Apple\Apple
0c34eb4351 🐛 fix(ability): keep case-sensitive (group, model) keys during deduplication
The previous patch lower-cased `group` and `model` when building the
temporary `abilitySet` used to prevent duplicate inserts.
This merged models that differ only by letter case, e.g.
`GPT-3.5-turbo` vs `gpt-3.5-turbo`, causing them to disappear from the
user’s available-models list and pricing page.

Change:
• ability.go – removed all `strings.ToLower` calls when composing the
  deduplication key (`group|model`), so duplicates are checked in a
  case-sensitive manner while preserving the original data.

Result:
• `GPT-3.5-turbo` and `gpt-3.5-turbo` are now treated as distinct
  models throughout the system.
2025-06-13 13:03:06 +08:00
Apple\Apple
215238332d 🐛 fix(ability): prevent duplicate (group, model) pairs when saving channels
When importing large model lists (≈700+) an attempt to save a channel
could fail with:

    Error 1062 (23000): Duplicate entry 'default-DeepSeek-1' for key 'abilities.PRIMARY'

Root cause: AddAbilities / UpdateAbilities inserted the same
(group, model) pair multiple times if the input list contained
duplicates or case-variants (e.g. `default` vs `Default`).

Changes:
• ability.go
  – AddAbilities: introduced `abilitySet` to deduplicate by
    lower-cased `group|model` key before batch-inserting.
  – UpdateAbilities: applied the same deduplication logic when
    rebuilding abilities inside a transaction.

Notes:
• The lower-casing is only for set comparison; the original
  `group` and `model` values are preserved when persisting to DB,
  so case sensitivity of stored data is unchanged.
• Batch chunking logic (lo.Chunk) and performance characteristics
  remain unaffected.

Fixes #1215
2025-06-13 12:39:54 +08:00
CaIon
adb2c39564 feat: add panic recovery and retry mechanism for InitChannelCache; improve batch deletion of abilities in FixAbility 2025-05-23 01:26:52 +08:00
Calcium-Ion
3dff0d498f 2025-01-05 22:01:36 +08:00
Calcium-Ion
e275229597 Fix channel model length issue
Fixes #691

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Calcium-Ion/new-api/issues/691?shareId=XXXX-XXXX-XXXX-XXXX).
2025-01-05 21:55:25 +08:00
CalciumIon
0a845ae69f fix: try to fix pgsql #682 2024-12-31 02:10:19 +08:00
CalciumIon
fe29ca04d5 feat: Implement batch tagging functionality for channels
- Added a new endpoint to batch set tags for multiple channels, allowing users to update tags efficiently.
- Introduced a new `BatchSetChannelTag` function in the controller to handle incoming requests and validate parameters.
- Updated the `BatchSetChannelTag` method in the model to manage database transactions and ensure data integrity during tag updates.
- Enhanced the ChannelsTable component in the frontend to support batch tag setting, including UI elements for user interaction.
- Updated localization files to include new translation keys related to batch operations and tag settings.
2024-12-25 14:19:00 +08:00
CalciumIon
325de98738 feat: 渠道标签分组 2024-11-19 01:13:18 +08:00
1808837298@qq.com
a3dbf21280 feat: pricing page support multi groups #487 2024-09-22 17:44:57 +08:00
CalciumIon
0a86ce013a fix: sqlite too many SQL variables 2024-06-26 19:51:23 +08:00
CaIon
97acc9e5c4 feat: add pricing page 2024-05-13 23:02:35 +08:00
Xyfacai
07724ce38c fix: 修复渠道一次性添加很多model失败
修复渠道一次性添加很多model并且group多
提示失败 too many SQL variables
2024-04-08 23:51:51 +08:00
CaIon
37ec213d08 feat: 支持未开启缓存下本地重试 2024-04-06 20:45:18 +08:00
CaIon
0bc9072dcf fix: GetRandomSatisfiedChannel 2024-04-04 19:37:33 +08:00
CaIon
fb992eeeac feat: 本地重试 2024-04-04 16:35:44 +08:00
CaIon
bc2b1112db fix: reroll action error 2024-03-14 00:43:32 +08:00
CaIon
9c8732cb77 fix: 修复渠道一致性问题 2024-01-12 14:57:03 +08:00
CaIon
0266cf4b7e fix: 修复渠道一致性问题 2024-01-12 14:36:15 +08:00
CaIon
3c91d7539c feat: able to fix channels 2024-01-10 13:23:43 +08:00
CaIon
85a1540a2e fix: 减少group和model字段长度为64 2024-01-08 10:08:20 +08:00
CaIon
433f7affe9 feat: 加入渠道加权随机功能 2023-12-27 19:00:47 +08:00
CaIon
ffbde7d751 支持设置模型按次计费 2023-12-21 20:14:04 +08:00
CaIon
dbdfebcc41 fix pgsql 2023-12-08 13:15:59 +08:00
AIASS Group
745ba3cea7 fix the issue of model repetition 2023-11-23 15:36:07 +08:00
CaIon
0f8e24897e 修复可用模型显示已禁用模型 2023-11-22 23:02:43 +08:00
CaIon
f88b65c11f 修复可用model重复显示bug 2023-11-21 16:58:31 +08:00
CaIon
3eb7843b2e 完善个人中心 2023-11-21 16:35:51 +08:00
Bryan
58b6c88f7b fix: fix postgresql support (#606)
* fix postgresql support

fixes #517

* fix: fix pg support

* chore: delete useless code

---------

Co-authored-by: JustSong <songquanpeng@foxmail.com>
2023-10-22 18:38:29 +08:00
JustSong
1016ef75b4 fix: fix gorm expression
Co-authored-by: 初音控灬 <xyfacai@gmail.com>
2023-09-18 23:11:37 +08:00
JustSong
489eeff433 fix: fix gorm expression
Co-authored-by: 初音控灬 <xyfacai@gmail.com>
2023-09-18 23:07:59 +08:00
JustSong
3935c70cd9 fix: fix random selection is not working when directly using database 2023-09-18 22:39:10 +08:00
JustSong
ebdab831e6 fix: fix priority not updated & random choice not working 2023-09-18 21:43:45 +08:00
Xyfacai
ead3b915ca feat: supprt channel priority now & record channel id in log (#484)
* feat: 支持设置渠道优先级 & 日志中显示使用的渠道ID

* fix: 设置渠道优先级未更新 ability

* chore: update implementation

---------

Co-authored-by: Xiangyuan Liu <xiangyuan.liu@ui.com>
Co-authored-by: JustSong <songquanpeng@foxmail.com>
Co-authored-by: JustSong <39998050+songquanpeng@users.noreply.github.com>
2023-09-17 19:18:16 +08:00
JustSong
f158d754ef fix: fix the wrong message when channel is deleted 2023-06-29 11:27:34 +08:00
JustSong
d27698eedf feat: now one channel can belong to multiple groups (close #153) 2023-06-14 12:14:08 +08:00
JustSong
ac11307faf refactor: enable model configuration on default group (close #143) 2023-06-09 18:05:51 +08:00