Commit Graph

60 Commits

Author SHA1 Message Date
CaIon
d1f3f2c395 fix(token_counter): update token counting logic to handle media token conditions 2025-08-27 17:11:33 +08:00
CaIon
d92c9db61c fix(image): add error handling for empty base64 string in image decoding 2025-08-27 16:38:32 +08:00
CaIon
3a90d5054c feat: implement file type detection from URL with enhanced MIME type handling 2025-08-16 14:56:29 +08:00
CaIon
77b100ba2b refactor: update function signatures to include context and improve file handling #1599 2025-08-15 18:40:54 +08:00
CaIon
07137e6bb8 refactor: update token type handling and improve token counting logic 2025-08-15 13:28:03 +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
14cca53ec8 🔧 refactor(endpoint types): comment out unused endpoint types in constants 2025-07-04 15:53:46 +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
16997a695d refactor: token counter logic 2025-06-21 00:54:40 +08:00
CaIon
5511ba3670 🔧 fix(stream_scanner): improve resource management and error handling in StreamScannerHandler 2025-06-11 00:18:16 +08:00
CaIon
7dc7805c6a 🔧 fix(token_counter): enhance token encoder caching and concurrency handling 2025-06-10 18:55:21 +08:00
CaIon
1abd77c17c 🔧 fix(token_counter): refactor token encoder initialization and retrieval logic 2025-06-10 18:51:26 +08:00
CaIon
88a801af2d 🔧 fix(token_counter): update token encoder implementation and dependencies 2025-06-10 18:04:49 +08:00
Xyfacai
8343fe0740 refactor: message content 改成 any
refactor: message content 改成 any
2025-06-07 23:47:22 +08:00
CaIon
c0d85e2d98 feat: enhance image decoding logic to handle base64 file types and improve error handling 2025-05-15 14:51:33 +08:00
CaIon
4bf0d094c4 feat: add video URL support in MediaContent and update token counting logic 2025-05-03 21:12:07 +08:00
CaIon
b364e9e3b1 refactor: simplify model prefix checks and update message role for o-series models 2025-04-17 16:50:52 +08:00
CaIon
577b18a1a1 feat: enhance file handling and logging in the application 2025-04-11 16:23:54 +08:00
1808837298@qq.com
b93827c425 feat: support dify upload image file 2025-03-15 19:10:12 +08:00
1808837298@qq.com
78fc3a191c feat: claude relay 2025-03-12 21:31:46 +08:00
1808837298@qq.com
b640118d74 feat: Implement cache token ratio for more precise token pricing 2025-03-08 01:30:50 +08:00
1808837298@qq.com
485face2c0 feat: Add self-use mode for model ratio and price configuration
- Introduce `SelfUseModeEnabled` setting to allow flexible model ratio configuration
- Update error handling to provide more informative messages when model ratios are not set
- Modify pricing and relay logic to support self-use mode
- Add UI toggle for enabling self-use mode in operation settings
- Implement fallback mechanism for model ratios when self-use mode is enabled
2025-03-01 21:13:48 +08:00
1808837298@qq.com
0646fa1892 fix: gemini&claude tool call format #795 #766 2025-02-26 23:56:10 +08:00
1808837298@qq.com
fd44ac7c0c feat: Enhance token counting and content parsing for messages 2025-02-24 14:18:15 +08:00
1808837298@qq.com
61ad1adbda feat: Improve embedding request handling and support across channels
- Update EmbeddingRequest DTO to support more flexible input types
- Add input parsing method to handle various input formats
- Implement ConvertEmbeddingRequest for multiple channel adaptors
- Remove relayMode parameter from EmbeddingHelper
- Add input validation for embedding requests
- Simplify embedding request conversion for different channels
2025-02-12 14:39:36 +08:00
1808837298@qq.com
16afc5b3d6 fix: retry prompt tokens 2025-01-02 16:33:00 +08:00
CalciumIon
e326679b72 feat: add multi-file type support for Gemini and Claude
- Add file data DTO for structured file handling
- Implement file decoder service
- Update Claude and Gemini relay channels to handle various file types
- Reorganize worker service to cf_worker for clarity
- Update token counter and image service for new file types
2024-12-29 00:00:24 +08:00
CalciumIon
5bbc730a6f feat: update o1 default token encoder 2024-12-27 15:03:10 +08:00
CalciumIon
62469a5226 feat: support azure stream_options 2024-12-26 22:51:06 +08:00
1808837298@qq.com
efd7ea075e feat: azure realtime
(cherry picked from commit 75ff3d98f06103dc2df1f8817bd3fcbf433e0f20)
2024-11-05 19:27:55 +08:00
1808837298@qq.com
1307a23f01 feat: realtime
(cherry picked from commit d4966246e68dbdcdab45ec5c5141362834d74425)
2024-11-05 19:27:47 +08:00
1808837298@qq.com
9e4133a890 feat: realtime
(cherry picked from commit a5529df3e1a4c08a120e8c05203a7d885b0fe8d8)
2024-11-05 19:24:14 +08:00
CalciumIon
c5633221f0 feat: support gpt-4o-audio-preview 2024-11-04 15:27:12 +08:00
CalciumIon
28c9675e61 feat: update chatgpt-4o token encoder 2024-09-05 18:35:34 +08:00
CalciumIon
09401526dc feat: support gpt-4o-mini image tokens 2024-07-19 12:59:37 +08:00
CalciumIon
34c356b041 feat: 媒体请求计费选项 2024-07-18 17:04:19 +08:00
1808837298@qq.com
1f4770fa50 feat: update token encoder 2024-05-30 23:15:06 +08:00
1808837298@qq.com
1760ec1396 Merge remote-tracking branch 'origin/main' 2024-05-30 21:46:22 +08:00
1808837298@qq.com
2254b1c422 feat: update tiktoken 2024-05-30 21:45:58 +08:00
1808837298@qq.com
893dafb89f feat: 支持设置worker访问请求中的图片地址 2024-05-28 17:59:53 +08:00
1808837298@qq.com
f723ff9ba0 feat: 增加重置模型倍率功能 (close #62) 2024-05-24 15:28:16 +08:00
1808837298@qq.com
313c16f360 refactor: 重构敏感词 2024-05-23 23:59:55 +08:00
CaIon
e65b85d649 chore: token counter 2024-05-18 15:14:49 +08:00
CaIon
8563334f4c chore: update InitTokenEncoders (#255) 2024-05-15 16:32:00 +08:00
CaIon
456be72de2 chore: update tiktoken (#254) 2024-05-15 14:18:29 +08:00
CaIon
8e3c527640 fix: 规范claude返回格式 2024-04-26 02:56:35 +08:00
CaIon
d0500cf1e2 fix: close #218 2024-04-24 14:44:24 +08:00
CaIon
22aaa61078 refactor: 重构计费代码 2024-04-23 23:51:27 +08:00
CaIon
86ab64ec67 feat: 完善函数计费 2024-04-23 23:01:06 +08:00