Commit Graph

184 Commits

Author SHA1 Message Date
CaIon
3401abe4d2 fix(relay-gemini): update media handling in candidate content processing 2025-08-27 12:14:50 +08:00
Sh1n3zZ
8a1f6534fc feat: imagen for vertex channel 2025-08-18 21:49:55 +08:00
CaIon
61601d38c4 feat: 完善gemini格式转换 2025-08-17 19:08:06 +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
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
32978f9cd9 feat: Simplify response handling by returning raw response body directly 2025-08-11 20:07:24 +08:00
CaIon
ce74e94fc7 feat: Refactor Gemini tools handling to support JSON raw message format 2025-08-11 19:48:04 +08:00
RedwindA
f5a52bc5b5 feat: update dto for embeddings 2025-08-09 18:31:56 +08:00
RedwindA
1dcb9a01ce Merge branch 'alpha' into 'feat/support-native-gemini-embedding' 2025-08-09 18:05:11 +08:00
Calcium-Ion
2c4dc44661 Merge pull request #1500 from antecanis8/gemini_batchembedcontents
fix: Gemini embedding model only embeds the first text in a batch
2025-08-09 11:42:08 +08:00
RedwindA
74057324b2 fix typo; add ParamOverride for Gemini Embedding 2025-08-09 01:07:48 +08:00
RedwindA
8127ad9929 feat: support native Gemini Embedding 2025-08-09 00:27:33 +08:00
CaIon
5b5b97eb30 feat: 完善格式抓换,修复gemini渠道和openai渠道在claude code中使用的问题 2025-08-08 16:45:37 +08:00
Calcium-Ion
cdc6ab61df Merge pull request #1518 from RedwindA/fix/disable-gemini-sse
Fix/disable-gemini-ping
2025-08-07 20:44:24 +08:00
CaIon
a4b02107dd feat: update MaxTokens handling 2025-08-07 16:15:59 +08:00
RedwindA
342bf59c91 fix: 调整Disable Ping标志的设置位置 2025-08-07 06:18:22 +08:00
CaIon
2e41362f2e fix: update budget calculation logic in relay-gemini to use clamping function 2025-08-06 16:25:48 +08:00
CaIon
6960a06322 feat: enhance ThinkingAdaptor with effort-based budget clamping and extra body handling 2025-08-06 16:20:38 +08:00
antecanis8
4a5bd6938b feat: add support for configuring output dimensionality for multiple Gemini new models 2025-08-04 14:19:19 +00:00
antecanis8
ded1cde2ff fix : Gemini embedding model only embeds the first text in a batch 2025-08-04 13:02:57 +00:00
Xyfacai
bb08de0b11 fix: 修复gemini2openai 没有返回 usage 2025-08-04 09:06:57 +08:00
CaIon
f0b024eb77 feat: enhance ConvertGeminiRequest to set default role and handle YouTube video MIME type 2025-08-02 12:53:58 +08:00
creamlike1024
502c5dde9c Merge remote-tracking branch 'origin/alpha' into ConvertGeminiRequest 2025-08-01 22:42:48 +08:00
creamlike1024
689dbfe71a feat: convert gemini format to openai chat completions 2025-08-01 22:23:35 +08:00
CaIon
2578c39c7d refactor: simplify streamResponseGeminiChat2OpenAI by removing hasImage return value and optimizing response text handling 2025-08-01 17:58:21 +08:00
CaIon
87c16db2d7 fix: update JSONEditor to default to manual mode for invalid JSON and add error message for invalid data 2025-08-01 17:21:25 +08:00
CaIon
de23f66785 fix: handle case where no response is received from Gemini API 2025-08-01 17:04:16 +08:00
CaIon
563d056ff7 refactor: update error handling to support dynamic error types 2025-07-31 21:16:01 +08:00
creamlike1024
1bb8a314cb Merge branch 'fix/gemini-native-sse' of github.com:RedwindA/new-api into RedwindA-fix/gemini-native-sse 2025-07-30 20:34:12 +08:00
CaIon
2db71673a5 fix: auto ban 2025-07-30 18:39:19 +08:00
CaIon
a1caf37f5b fix: auto ban 2025-07-29 15:20:08 +08:00
CaIon
360012bed2 feat: support claude convert to gemini 2025-07-26 13:31:33 +08:00
CaIon
2cb7b9ae62 fix: improve error messaging and JSON schema handling in distributor and relay components 2025-07-26 12:11:20 +08:00
RedwindA
20c132bf13 禁用原生Gemini模式中的ping保活 2025-07-18 23:39:01 +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
e2c34bdeb9 🐛 fix: refactor JSON unmarshalling across multiple handlers to use UnmarshalJson and UnmarshalJsonStr for consistency
This update replaces instances of DecodeJson and DecodeJsonStr with UnmarshalJson and UnmarshalJsonStr in various relay handlers, enhancing code consistency and clarity in JSON processing. The changes improve maintainability and align with recent refactoring efforts in the codebase.
2025-06-28 00:02:07 +08:00
CaIon
ae586e1be9 feat: add CloseResponseBodyGracefully function to handle HTTP response body closure 2025-06-27 21:37:13 +08:00
CaIon
7de52a0c0d feat(gemini): enhance ThinkingAdapter and model handling
- Introduced `isNoThinkingRequest` and `trimModelThinking` functions to manage model names and thinking configurations.
- Updated `GeminiHelper` to conditionally adjust the model name based on the thinking budget and request settings.
- Refactored `ThinkingAdaptor` to streamline the integration of thinking capabilities into Gemini requests.
- Cleaned up commented-out code in `FetchUpstreamModels` for clarity.

These changes improve the handling of model configurations and enhance the adaptability of the Gemini relay system.
2025-06-21 21:50:03 +08:00
CaIon
d244915111 feat(relay-gemini): conditionally set ThinkingBudget based on MaxOutputTokens 2025-06-21 17:51:13 +08:00
Calcium-Ion
c60d87067d Merge pull request #1248 from RedwindA/update-gemini-ratio
feat(model-ratio): add default ratios for new Gemini models and refine flash model handling
2025-06-21 04:51:41 +08:00
CaIon
2c0fd2915b fix: improve usage calculation in GeminiTextGenerationStreamHandler 2025-06-21 01:08:15 +08:00
CaIon
16997a695d refactor: token counter logic 2025-06-21 00:54:40 +08:00
creamlike1024
4f3024ad63 fix: gemini 原生格式流模式中断请求未计费 2025-06-20 23:01:10 +08:00
CaIon
8ceaaf7819 fix: update response handling in GeminiTextGenerationStreamHandler
- Changed response handling from ObjectData to StringData for improved data processing.
- Ensured proper error logging in case of response handling failure.
2025-06-20 21:55:28 +08:00
CaIon
13277cf838 feat: implement new handlers for audio, image, embedding, and responses processing
- Added new handlers: AudioHelper, ImageHelper, EmbeddingHelper, and ResponsesHelper to manage respective requests.
- Updated ModelMappedHelper to accept request parameters for better model mapping.
- Enhanced error handling and validation across new handlers to ensure robust request processing.
- Introduced support for new relay formats in relay_info and updated relevant functions accordingly.
2025-06-20 16:02:23 +08:00
CaIon
2b2e0a4777 feat: enhance error handling in GeminiHelper and streamline response processing
- Added status code mapping handling in GeminiHelper to reset status codes based on response.
- Removed redundant candidate check in GeminiTextGenerationHandler to simplify response processing.
2025-06-20 01:42:19 +08:00
RedwindA
50907a5758 Merge remote-tracking branch 'upstream/alpha' into update-gemini-ratio 2025-06-19 20:02:27 +08:00
CaIon
05aaf63337 Merge branch 'alpha' 2025-06-19 16:17:56 +08:00
creamlike1024
1271f8f648 update relay-gemini-native.go 2025-06-19 14:50:50 +08:00