coding-proxy 0.1.2__py3-none-any.whl → 0.1.3a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of coding-proxy might be problematic. Click here for more details.
- coding/proxy/vendors/anthropic.py +59 -2
- {coding_proxy-0.1.2.dist-info → coding_proxy-0.1.3a1.dist-info}/METADATA +1 -1
- {coding_proxy-0.1.2.dist-info → coding_proxy-0.1.3a1.dist-info}/RECORD +6 -6
- {coding_proxy-0.1.2.dist-info → coding_proxy-0.1.3a1.dist-info}/WHEEL +0 -0
- {coding_proxy-0.1.2.dist-info → coding_proxy-0.1.3a1.dist-info}/entry_points.txt +0 -0
- {coding_proxy-0.1.2.dist-info → coding_proxy-0.1.3a1.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,11 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import copy
|
|
6
|
+
import logging
|
|
5
7
|
from typing import Any
|
|
6
8
|
|
|
7
9
|
from ..config.schema import AnthropicConfig, FailoverConfig
|
|
8
10
|
from .base import PROXY_SKIP_HEADERS, BaseVendor
|
|
9
11
|
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
# 需要从 assistant messages 中剥离的 thinking block 类型
|
|
15
|
+
_THINKING_BLOCK_TYPES = {"thinking", "redacted_thinking"}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _strip_thinking_blocks(body: dict[str, Any]) -> int:
|
|
19
|
+
"""从 assistant messages 中移除 thinking / redacted_thinking blocks.
|
|
20
|
+
|
|
21
|
+
Anthropic API 要求 thinking blocks 的 ``signature`` 必须是其签发的有效签名。
|
|
22
|
+
跨供应商迁移(如 Zhipu → Anthropic)后,conversation history 中可能包含
|
|
23
|
+
非 Anthropic 签发的 signature,导致 400 ``invalid_request_error``。
|
|
24
|
+
根据 Anthropic 官方文档,thinking blocks 可以被安全省略,不影响模型行为。
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
被移除的 thinking block 数量。
|
|
28
|
+
"""
|
|
29
|
+
stripped = 0
|
|
30
|
+
for message in body.get("messages", []):
|
|
31
|
+
if not isinstance(message, dict) or message.get("role") != "assistant":
|
|
32
|
+
continue
|
|
33
|
+
content = message.get("content")
|
|
34
|
+
if not isinstance(content, list):
|
|
35
|
+
continue
|
|
36
|
+
original_len = len(content)
|
|
37
|
+
new_content = [
|
|
38
|
+
block
|
|
39
|
+
for block in content
|
|
40
|
+
if not (
|
|
41
|
+
isinstance(block, dict) and block.get("type") in _THINKING_BLOCK_TYPES
|
|
42
|
+
)
|
|
43
|
+
]
|
|
44
|
+
removed = original_len - len(new_content)
|
|
45
|
+
if removed and not new_content:
|
|
46
|
+
logger.warning(
|
|
47
|
+
"anthropic: assistant message content became empty after "
|
|
48
|
+
"stripping %d thinking block(s); this may cause API errors",
|
|
49
|
+
removed,
|
|
50
|
+
)
|
|
51
|
+
message["content"] = new_content
|
|
52
|
+
stripped += removed
|
|
53
|
+
return stripped
|
|
54
|
+
|
|
10
55
|
|
|
11
56
|
class AnthropicVendor(BaseVendor):
|
|
12
57
|
"""Anthropic 官方 API 供应商.
|
|
@@ -37,11 +82,23 @@ class AnthropicVendor(BaseVendor):
|
|
|
37
82
|
request_body: dict[str, Any],
|
|
38
83
|
headers: dict[str, str],
|
|
39
84
|
) -> tuple[dict[str, Any], dict[str, str]]:
|
|
40
|
-
"""
|
|
85
|
+
"""深拷贝请求体、剥离历史 thinking blocks,过滤无关请求头.
|
|
86
|
+
|
|
87
|
+
深拷贝确保 Anthropic 的请求体修改不会污染后续 tier 的输入。
|
|
88
|
+
剥离 thinking blocks 防止跨供应商 signature 不兼容导致 400 错误。
|
|
89
|
+
"""
|
|
90
|
+
body = copy.deepcopy(request_body)
|
|
91
|
+
stripped = _strip_thinking_blocks(body)
|
|
92
|
+
if stripped:
|
|
93
|
+
logger.debug(
|
|
94
|
+
"anthropic: stripped %d thinking block(s) from conversation history",
|
|
95
|
+
stripped,
|
|
96
|
+
)
|
|
97
|
+
|
|
41
98
|
filtered = {
|
|
42
99
|
k: v for k, v in headers.items() if k.lower() not in PROXY_SKIP_HEADERS
|
|
43
100
|
}
|
|
44
|
-
return
|
|
101
|
+
return body, filtered
|
|
45
102
|
|
|
46
103
|
|
|
47
104
|
# 向后兼容别名
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: coding-proxy
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3a1
|
|
4
4
|
Summary: A High-Availability, Transparent, and Smart Multi-Vendor Proxy for Claude Code. Support Claude Plans, GitHub Copilot, Google Antigravity, ZAI/GLM.
|
|
5
5
|
Project-URL: Source Code, https://github.com/ThreeFish-AI/coding-proxy
|
|
6
6
|
Project-URL: User Guide, https://github.com/ThreeFish-AI/coding-proxy/blob/master/docs/user-guide.md
|
|
@@ -61,7 +61,7 @@ coding/proxy/server/routes.py,sha256=QeEsYczjvPfVhOrED2qe1V6CpwVBZbQHs8dP0OGdGXQ
|
|
|
61
61
|
coding/proxy/streaming/__init__.py,sha256=0al5TC-zJt8Bz0CibTmd8WPza-Cs-qcuZWvT2fKPqHI,23
|
|
62
62
|
coding/proxy/streaming/anthropic_compat.py,sha256=cycYiJ-glN88OmfLTR7FroHRethONlEcK0PT78KqGbA,21202
|
|
63
63
|
coding/proxy/vendors/__init__.py,sha256=fehSpQ2-kUlZY6N8cNMGVJYMXspQmi3V4e0FgC4Ay4k,1011
|
|
64
|
-
coding/proxy/vendors/anthropic.py,sha256=
|
|
64
|
+
coding/proxy/vendors/anthropic.py,sha256=yz7pqPmsIullv-_mV6N3EK4OqjJ3geICDfp7vPxbSN0,3704
|
|
65
65
|
coding/proxy/vendors/antigravity.py,sha256=zVl2fguxyIy3OjkosZYr2n5tR8dEEIjxazBEXY7v6BQ,13300
|
|
66
66
|
coding/proxy/vendors/base.py,sha256=3f9jAWWuYm0d_TS59gIRSCfxijw6iwjmq-q1ugJicfg,14763
|
|
67
67
|
coding/proxy/vendors/copilot.py,sha256=qAFTO2xMqnawaFlvZS2a9-7f_UEkfODIFfDlgOBiQl4,29590
|
|
@@ -71,8 +71,8 @@ coding/proxy/vendors/copilot_urls.py,sha256=YxaR6zmPdrySzsotJx6PjNIu2JIGG6N1D8kZ
|
|
|
71
71
|
coding/proxy/vendors/mixins.py,sha256=eZd_vlsPCKUNOEWSxWTDDb5i24GUIE3_JZDsj5LMr08,2583
|
|
72
72
|
coding/proxy/vendors/token_manager.py,sha256=s10t4Com0jNnKGkPyJ_HpG5SjHrCEJvfArEOAaPKA_k,4189
|
|
73
73
|
coding/proxy/vendors/zhipu.py,sha256=R4SOI9hKYnPk7sifSswsJpaEyWH6x3Ijo5ZoZSzFw7s,9623
|
|
74
|
-
coding_proxy-0.1.
|
|
75
|
-
coding_proxy-0.1.
|
|
76
|
-
coding_proxy-0.1.
|
|
77
|
-
coding_proxy-0.1.
|
|
78
|
-
coding_proxy-0.1.
|
|
74
|
+
coding_proxy-0.1.3a1.dist-info/METADATA,sha256=G8g4hfIyoHpc2OrL_82NBtQjohDEhQrBmpUlubamjOM,10782
|
|
75
|
+
coding_proxy-0.1.3a1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
76
|
+
coding_proxy-0.1.3a1.dist-info/entry_points.txt,sha256=moIVzt5ho0Wk9B47LOo2SEAbhzuDDHWi-EfM30U0XBg,54
|
|
77
|
+
coding_proxy-0.1.3a1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
78
|
+
coding_proxy-0.1.3a1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|