Commit Graph

132 Commits

Author SHA1 Message Date
papersnake 47d7bca268 feat: support claude-opus-4-7 (#4293)
* feat: support claude-opus-4-7

* feat: summarized display for opus 4.7
2026-04-17 13:52:34 +08:00
CaIon 3cad6b9d7f fix(claude): improve handling of empty string content in OpenAI to Claude message conversion 2026-04-16 17:44:38 +08:00
CaIon 8b22161527 fix: set TopP to nil in Claude request configuration 2026-04-13 14:36:22 +08:00
zuiho c66636a0c7 fix: 采纳 CodeRabbit 建议,!Done 时也用 fallback 覆盖占位 CompletionTokens
message_start 阶段可能给 CompletionTokens 非零占位值,
只检查 == 0 不够,加上 !Done && fallback > current 条件。
2026-04-07 17:52:11 +08:00
zuiho f7cdc727df fix: Claude 流式断流时不再整份覆盖 usage,保留 cache 计费字段
HandleStreamFinalResponse 在 !Done 时调用 ResponseText2Usage 整份覆盖
claudeInfo.Usage,导致 message_start 已获取的 CacheReadInputTokens、
CacheCreationInputTokens 等字段丢失,prompt 退化为占位值 1。

修复:
- 只补缺失的 CompletionTokens/PromptTokens,保留已有 cache 数据
- PromptTokens 兜底改用 info.GetEstimatePromptTokens()(与其他渠道对齐)

Fixes #4127
2026-04-07 17:41:08 +08:00
CaIon 03758a4a85 refactor(file-source): unify file source creation and enhance caching mechanisms 2026-04-06 15:54:55 +08:00
Seefs 82c2008d2c fix: emit claude message_delta for usage-only final stream chunk 2026-04-04 20:21:13 +08:00
CaIon bb5b9eaca2 fix(relay-claude): set TopP to nil in Claude request to align with API requirements 2026-04-03 20:18:28 +08:00
Calcium-Ion 41cd051ea9 Merge pull request #3505 from seefs001/fix/claude-media-support
fix: add basic inline file support for Claude relay
2026-04-02 13:29:21 +08:00
Seefs c04f82bfb5 TODO: fix chat -> messages file type 2026-04-02 13:16:58 +08:00
CaIon 5238f279db feat: record stream interruption reasons via StreamStatus
- Add StreamStatus type (relay/common) to track stream end reason
  (done/timeout/client_gone/scanner_error/eof/panic/ping_fail) and
  accumulate soft errors during streaming via sync.Once + sync.Mutex.
- Add StreamResult (relay/helper) as the callback interface: adapters
  call sr.Error() for soft errors, sr.Stop() for fatal, sr.Done() for
  normal completion. No early-return problem — multiple errors per chunk
  are naturally supported.
- Refactor StreamScannerHandler callback from func(string) bool to
  func(string, *StreamResult). All 9 channel adapters updated.
- Write stream_status into log other JSON field (admin-only) with
  status ok/error, end_reason, error_count, and error messages.
- Frontend: display stream status in log detail expansion for admins.
2026-03-31 16:54:39 +08:00
Seefs 263b9bc695 fix: add basic inline file support for Claude relay 2026-03-30 19:37:21 +08:00
Seefs 9ecad90652 refactor: optimize billing flow for OpenAI-to-Anthropic convert 2026-03-23 14:22:12 +08:00
Seefs 618fce621b Revert "fix: aws text content blocks must be non-empty" 2026-03-02 19:43:00 +08:00
Seefs 04954f1058 Revert "Fix/aws non empty text" 2026-03-02 19:40:53 +08:00
Seefs 7cc8ec2c91 fix: tool responses 2026-03-02 19:22:37 +08:00
Seefs 2df604bbad fix: default empty input_json_delta arguments to {} for tool call parsing 2026-03-02 15:51:55 +08:00
Seefs da11617776 fix: preserve tool_use on malformed tool arguments to keep tool_result pairing valid 2026-03-02 15:41:03 +08:00
Seefs 4d6f9a94a3 fix: aws text content blocks must be non-empty 2026-03-02 15:31:37 +08:00
Seefs 2cf3c1836c fix: preserve explicit zero values in native relay requests 2026-03-01 15:47:03 +08:00
Seefs 81a94c3027 fix: patch message_delta usage via gjson/sjson and skip on passthrough 2026-02-07 19:13:58 +08:00
Thomas 63f246d403 fix: 补全 streaming message_delta 事件缺失的 input_tokens 和 cache 相关字段 (#2881)
当上游为 AWS Bedrock 时,message_delta 的 usage 可能缺少 input_tokens、
cache_creation_input_tokens、cache_read_input_tokens 等字段,导致与原生
Anthropic 格式不一致。从 message_start 积累的 claudeInfo 中补全这些字段后
重新序列化,确保客户端收到一致的 usage 格式。
2026-02-07 18:17:22 +08:00
Papersnake e194b747c3 feat: support adaptive thinking 2026-02-06 11:01:23 +08:00
CaIon 330e1e6395 remove: drop support for claude-2 and claude-1 series models
- Remove claude-instant-1.2, claude-2, claude-2.0, claude-2.1 from model lists
- Remove /v1/complete endpoint support (legacy completion API)
- Remove RequestModeCompletion and related code paths
- Simplify handler functions by removing requestMode parameter
- Update all channel adaptors that referenced claude handlers
2026-02-05 17:20:46 +08:00
CaIon 9ef9e78821 feat(file): unify file handling with a new FileSource abstraction for URL and base64 data 2026-02-04 18:23:17 +08:00
Seefs 4f786a3591 Merge pull request #2811 from seefs001/fix/openrouter-claude-cache-usage
fix: openrouter claude cache usage
2026-02-03 00:03:19 +08:00
Seefs 06795ddf39 fix: claude panic 2026-02-02 15:03:30 +08:00
Seefs b063b25998 fix: disable_parallel_tool_use parameter should be removed for tool_choice=none: 2026-01-28 13:31:14 +08:00
Seefs d829958f53 fix: reason convert 2026-01-25 15:31:23 +08:00
Seefs 0e76cc3f67 feat: claude refusal reason 2026-01-25 15:21:31 +08:00
feitianbubu 1dc7ab9a97 fix: check claudeResponse delta StopReason nil point 2025-12-24 11:54:23 +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 fd55ba7f2c feat: ShouldPreserveThinkingSuffix (#2189) 2025-11-07 17:43:33 +08:00
Seefs e1b9317531 feat: claude 1h cache (#2155)
* feat: claude 1h cache

* feat: claude 1h cache

* fix price
2025-11-04 00:20:50 +08:00
yanggh b6f352735e fix(convert): 修复 OpenAI 转 Claude 流时 thinking 块的格式问题
将 `ClaudeMediaMessage.Thinking` 的类型从 `string` 修改为 `*string`,以解决 `omitempty` 导致 `"thinking": ""` 字段在 JSON 序列化时被忽略的问题。

同时更新了 `service/convert.go` 和 `relay/channel/claude/relay-claude.go` 中的相关逻辑,以兼容新的指针类型,确保生成的 Claude 事件流符合官方规范。
2025-10-13 19:32:17 +08:00
Seefs 5010f2d004 format: package name -> github.com/QuantumNous/new-api (#2017) 2025-10-11 15:30:09 +08:00
creamlike1024 bbfbce9c67 fix: claude header was not set correctly 2025-09-09 23:18:07 +08:00
Calcium-Ion b3e67d5ef7 Merge pull request #1692 from yunayj/alpha
修改claude system参数为数组,增加通用性
2025-09-08 14:55:48 +08:00
creamlike1024 de73bfff78 feat(relay-claude): mapping stop reason and send text delta on block start type
- convert claude stop reason "max_tokens" to openai "length"
- send content_block_start content text delta
2025-09-07 23:03:19 +08:00
yunayj fe71af943c 修改claude system参数为数组格式,提升API兼容性 2025-08-29 19:06:01 +08:00
Nekohy 57b1ddcc5f feats:Standardize ClaudeHandler, add zhipu_4v Anthropic native support 2025-08-18 13:14:48 +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 d37af13b33 feat: support qwen claude format 2025-08-07 18:32:31 +08:00
CaIon a4b02107dd feat: update MaxTokens handling 2025-08-07 16:15:59 +08:00
CaIon 563d056ff7 refactor: update error handling to support dynamic error types 2025-07-31 21:16:01 +08:00
Calcium-Ion a1609f36c7 Merge pull request #1384 from QuantumNous/RequestOpenAI2ClaudeMessage
feat: 改进 RequestOpenAI2ClaudeMessage 和添加 claude web search 计费
2025-07-17 19:15:54 +08:00
creamlike1024 e351642db9 feat: claude web search tool 计费 2025-07-15 18:57:22 +08:00