Commit Graph

36 Commits

Author SHA1 Message Date
Seefs
2cf3c1836c fix: preserve explicit zero values in native relay requests 2026-03-01 15:47:03 +08:00
CaIon
1fededceb3 feat: refactor token estimation logic
- Introduced new OpenAI text models in `common/model.go`.
- Added `IsOpenAITextModel` function to check for OpenAI text models.
- Refactored token estimation methods across various channels to use estimated prompt tokens instead of direct prompt token counts.
- Updated related functions and structures to accommodate the new token estimation approach, enhancing overall token management.
2025-12-02 21:34:39 +08:00
CaIon
c8bbf7bed8 feat: Add ContextKeyLocalCountTokens and update ResponseText2Usage to use context in multiple channels 2025-11-21 18:17:01 +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
a4b02107dd feat: update MaxTokens handling 2025-08-07 16:15:59 +08:00
creamlike1024
689dbfe71a feat: convert gemini format to openai chat completions 2025-08-01 22:23:35 +08:00
CaIon
5bf5d3d16a feat(adaptor): refactor response handlers to return usage first and improve error handling 2025-07-12 21:12:46 +08:00
CaIon
4a9ca4209a refactor: Introduce standardized API error
This commit refactors the application's error handling mechanism by introducing a new standardized error type, `types.NewAPIError`. It also renames common JSON utility functions for better clarity.

Previously, internal error handling was tightly coupled to the `dto.OpenAIError` format. This change decouples the internal logic from the external API representation.

Key changes:
- A new `types.NewAPIError` struct is introduced to serve as a canonical internal representation for all API errors.
- All relay adapters (OpenAI, Claude, Gemini, etc.) are updated to return `*types.NewAPIError`.
- Controllers now convert the internal `NewAPIError` to the client-facing `OpenAIError` format at the API boundary, ensuring backward compatibility.
- Channel auto-disable/enable logic is updated to use the new standardized error type.
- JSON utility functions are renamed to align with Go's standard library conventions (e.g., `UnmarshalJson` -> `Unmarshal`, `EncodeJson` -> `Marshal`).
2025-07-10 15:02:40 +08:00
CaIon
ae586e1be9 feat: add CloseResponseBodyGracefully function to handle HTTP response body closure 2025-06-27 21:37:13 +08:00
CaIon
16997a695d refactor: token counter logic 2025-06-21 00:54:40 +08:00
CaIon
288f279379 🔧 refactor(relay): replace UUID generation with helper function for response IDs 2025-06-16 21:02:27 +08:00
Xyfacai
8343fe0740 refactor: message content 改成 any
refactor: message content 改成 any
2025-06-07 23:47:22 +08:00
creamlike1024
8ea4c76f2b feat: support /v1/responses API 2025-05-02 13:59:46 +08:00
1808837298@qq.com
8918381c96 feat: support xinference rerank to jina format 2025-03-16 21:06:29 +08:00
TAKO
adbfdd0150 Sync Cohere Latest Model 2025-03-15 12:12:46 +08:00
1808837298@qq.com
47c297794d feat: 初步兼容流模式下openai渠道类型转为claude格式访问 #862 2025-03-13 19:32:08 +08:00
1808837298@qq.com
78fc3a191c feat: claude relay 2025-03-12 21:31:46 +08:00
1808837298@qq.com
d647214555 refactor: Centralize stream handling and helper functions in relay package 2025-03-05 19:47:41 +08:00
Jerry
fcc32ffbc9 Fix M3E not working 2025-01-23 05:54:39 +08:00
1808837298@qq.com
9e4133a890 feat: realtime
(cherry picked from commit a5529df3e1a4c08a120e8c05203a7d885b0fe8d8)
2024-11-05 19:24:14 +08:00
CalciumIon
f50cf75d1a fix: cohere SafetyMode 2024-09-11 19:12:32 +08:00
HynoR
c3f2f337aa Merge remote-tracking branch 'origin/main' 2024-09-02 06:47:58 +07:00
HynoR
b7b5887b0e Update Cohere Safety Setting 2024-09-02 06:47:49 +07:00
HynoR
619da9e832 Cohere Update 2024-09-01 15:21:05 +07:00
CalciumIon
ee0e1c9736 refactor: audio relay 2024-07-16 22:07:10 +08:00
CalciumIon
7b20b4ed3d fix: azure stream options 2024-07-15 16:05:30 +08:00
CalciumIon
fe4665fd99 feat: support cloudflare worker ai 2024-07-13 19:55:22 +08:00
CalciumIon
8afed8823e chore: remove useless code 2024-07-06 17:29:28 +08:00
CalciumIon
e3256db6d0 fix: fix rerank 2024-07-06 17:28:00 +08:00
CalciumIon
c7ba4a245b feat: support cohere rerank 2024-07-06 17:09:22 +08:00
CalciumIon
054c96d6fb feat: support cohere first response time 2024-06-28 23:32:02 +08:00
CaIon
483e1c46d2 fix: 规范claude返回格式 2024-04-25 23:57:39 +08:00
CaIon
0326758fc8 fix typo 2024-04-24 22:53:58 +08:00
CaIon
cae9dbe141 feat: support cohere (close #195) 2024-04-24 18:49:56 +08:00